[Coding Help] ALT Text from database string

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
User avatar
GoleyC
Registered User
Posts: 374
Joined: Thu Mar 14, 2002 5:22 pm
Location: Ohio
Contact:

[Coding Help] ALT Text from database string

Post by GoleyC » Thu Oct 03, 2002 12:35 am

I'll have to explain what I'm up to and maybe someone could shade some light on my faults with my code.

I'm using the Sponsor Category MOD. However, I would like to display the "alt" code for images when a mouse hovers over it to what ever is in the database. I've setup the alt database field, populated it with text. Using the "original code" below, all works fine, except it will not pull in from the database the "alt" code.

So, I did some modifications to the string of code below in hopes to get it to work. However, the code below will not pull in the "alt" text which is in the database.

Maybe someone could point me in the right direction.

Original Code

Code: Select all

'SPONSOR' => ( $category_rows[$i]['cat_sponsor_img'] ? ( $category_rows[$i]['cat_sponsor_url'] ? '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">' : '' ) . '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" />' : '' ),
Modified Code Below which errors out

Code: Select all

'SPONSOR' =>
 ( $category_rows[$i]['cat_sponsor_img'] ? ( $category_rows[$i]['cat_sponsor_url'] ? ( $category_rows[$i]['cat_sponsor_alt'] ? '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">' : '' ) . '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" . alt="' . $category_rows[$i]['cat_sponsor_alt']'" />' : '' ),
Error Message that comes back

Code: Select all

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/atv/public_html/atva/index.php on line 318
I've tried every variation I can think of and still cannot get it to pull in the text, it just errors out.

phpBB Version 2.0.3

If anyone could give me some hints on what I'm doing wrong, that would be awesome.

All the best!
CG

Acyd Burn
Consultant
Consultant
Posts: 5830
Joined: Wed Dec 05, 2001 8:31 pm
Location: Behind You
Name: Meik Sievertsen

Re: [Coding Help] ALT Text from database string

Post by Acyd Burn » Thu Oct 03, 2002 12:46 pm

GoleyC wrote: Modified Code Below which errors out

Code: Select all

'SPONSOR' =>
 ( $category_rows[$i]['cat_sponsor_img'] ? ( $category_rows[$i]['cat_sponsor_url'] ? ( $category_rows[$i]['cat_sponsor_alt'] ? '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">' : '' ) . '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" . alt="' . $category_rows[$i]['cat_sponsor_alt']'" />' : '' ),
Error Message that comes back

Code: Select all

Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/atv/public_html/atva/index.php on line 318


Use this one instead:

Code: Select all

'SPONSOR' => ( $category_rows[$i]['cat_sponsor_img'] ? ( $category_rows[$i]['cat_sponsor_url'] ? ( $category_rows[$i]['cat_sponsor_alt'] ? '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">' : '' ) . '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" . alt="' . $category_rows[$i]['cat_sponsor_alt']'" />' : '' )),

User avatar
GoleyC
Registered User
Posts: 374
Joined: Thu Mar 14, 2002 5:22 pm
Location: Ohio
Contact:

Re: [Coding Help] ALT Text from database string

Post by GoleyC » Thu Oct 03, 2002 1:15 pm

Acyd Burn wrote: Use this one instead:

Code: Select all

'SPONSOR' => ( $category_rows[$i]['cat_sponsor_img'] ? ( $category_rows[$i]['cat_sponsor_url'] ? ( $category_rows[$i]['cat_sponsor_alt'] ? '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">' : '' ) . '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" . alt="' . $category_rows[$i]['cat_sponsor_alt']'" />' : '' )),


It stills errors out:

Here's the error message:
Parse error: parse error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/atv/public_html/atva/index.php on line 318

The spaces in the script were taken out of the first post so it wasn't the spaces that was causing the problem.

Any other ideas?
CG

Acyd Burn
Consultant
Consultant
Posts: 5830
Joined: Wed Dec 05, 2001 8:31 pm
Location: Behind You
Name: Meik Sievertsen

Re: [Coding Help] ALT Text from database string

Post by Acyd Burn » Thu Oct 03, 2002 1:28 pm

Ok, a much more cleaner way. Before $template->assign_vars( add this:

Code: Select all

$sponsor = '';

if ($category_rows[$i]['cat_sponsor_img'])
{
	if ($category_rows[$i]['cat_sponsor_url'])
	{
		$sponsor .= '<a href="' . $category_rows[$i]['cat_sponsor_url'] . '">';
	}

	if ($category_rows[$i]['cat_sponsor_alt'])
	{
		$sponsor .= '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" alt="' . $category_rows[$i]['cat_sponsor_alt'] . '" />';
	}
	else
	{
		$sponsor .= '<img src="' . $category_rows[$i]['cat_sponsor_img'] . '" border="0" />';
	}

	if ($category_rows[$i]['cat_sponsor_url'])
	{
		$sponsor .= '</a>';
	}
}
Now only assign $sponsor.

Code: Select all

'SPONSOR' => $sponsor,
Now it's much much easier to read, modify and find errors. :) (The code should work now.)

edit: changed code a bit, some logical errors were there.

User avatar
GoleyC
Registered User
Posts: 374
Joined: Thu Mar 14, 2002 5:22 pm
Location: Ohio
Contact:

THANKS!

Post by GoleyC » Thu Oct 03, 2002 4:06 pm

THANKS!

That did the trick.... :lol: :P :wink: :D :o
CG

Post Reply

Return to “[2.0.x] MOD Writers Discussion”