View Full Version : Trying to get php to fill in alt tags

11-04-2007, 01:37 PM
I have been tying to use php to create alt tags that pull data from a mysql database. So for instance the alt tag could show the region, price and country etc by pulling that info from a table.

This is what I have currently:

$im_array = explode("|", $a1[image]);

//$FirstImage = "<img src=\"re_images/$im_array[0]\" width=100 height=100>";
$FirstImage = "<img src=\"thumbnails/$im_array[0]\">";

Should it be something like:

//$FirstImage = "<img src=\"re_images/$im_array[0]\" width=100 height=100>";
$FirstImage = '<img src=\"thumbnails/$im_array[0]\alt="'.$a1['region'].', '.$a1['country'].'">";

But with this i get this error :
Parse error: syntax error, unexpected T_LNUMBER

on this line:

if($i == '2')
$Image2 = "bg_photos2.gif";

$MyImages = explode("|", $a1[image]);

Any one know why?

11-04-2007, 02:08 PM
$FirstImage = '<img src="thumbnails/{$im_array[0]}" alt="'.$a1['region'].', '.$a1['country'].'">"';

11-04-2007, 02:30 PM
Thanks for your help!! :) It sort of works. What i get now is no image, so a white box with a red cross in it and the correct alt tag in that. So I now have an alt tag but no image?

Using this code the code to begin with is all greyed out and when I change this the code after it become black not grey. Does this mean it hasn't been closed off or finished properly?

$FirstImage = '<img src="thumbnails/{$im_array[0]}" alt="'.$a1['state'].', '.$a1['country'].'">"';

Has it got anything to do with the later coding:

}if($i == '2')
{$Image2 = "bg_photos2.gif";
{$MyImages = explode("|", $a1[image]);
$ShowInfo .= "<table valign=top align=center width=\"500\" height=60>\n<tr>\n\t<td align=center valign=top width=\"500\" height=60>";
while(list(,$v) = each($MyImages))
{ $ShowInfo .= "<a href=\"info.php?id=$_GET[id]&i=$_GET[i]&f=$v\"><img src=\"thumbnails/$v\" width=100 height=100 border=0></a>&nbsp;&nbsp;&nbsp;\n\n\t"; }

$ShowInfo .= "</table><hr size=1 width=\"95%\" color=#336699><br>";

{$ShowInfo .= "<center><img src=\"re_images/$f\"></center><br>";}
{$ShowInfo .= "<center><img src=\"re_images/$MyImages[0]\"></center><br>";}

11-05-2007, 11:05 PM
Thanks for that. In the source code i get this from the code above: <img src="thumbnails/{$im_array[0]}" alt="alicante, Spain">

But from the original code I get: <img src="thumbnails/1174243258_offer_16.jpg">

So it's not finding the image any more. Does anyone know why?

11-06-2007, 01:02 AM
Because the path to the image is wrong?

11-06-2007, 04:58 PM
$FirstImage = '<img src="thumbnails/{$im_array[0]}" alt="'

Single quotes are not parsed for variables.

$FirstImage = '<img src="thumbnails/'.$im_array[0].'" alt="'

11-07-2007, 06:59 PM
Thank you!! It works!

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum