Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation Trying to get php to fill in alt tags

    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:
    PHP Code:
    if(!empty($a1[image]))
        {
            
    $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:
    PHP Code:
    //$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";

    if(!empty($a1[image]))
    {
    $MyImages = explode("|", $a1[image]);


    Any one know why?

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Wales
    Posts
    820
    Thanks
    1
    Thanked 82 Times in 79 Posts
    Code:
    $FirstImage = '<img src="thumbnails/{$im_array[0]}" alt="'.$a1['region'].', '.$a1['country'].'">"';

  • Users who have thanked Mwnciau for this post:

    pp4sale (11-04-2007)

  • #3
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation

    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?
    PHP Code:
    $FirstImage '<img src="thumbnails/{$im_array[0]}" alt="'.$a1['state'].', '.$a1['country'].'">"'

    Has it got anything to do with the later coding:

    PHP Code:
    }if($i == '2')
    {
    $Image2 "bg_photos2.gif";
    if(!empty(
    $a1[image]))
    {
    $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>";

    if(!empty(
    $f))
    {
    $ShowInfo .= "<center><img src=\"re_images/$f\"></center><br>";}
    else
    {
    $ShowInfo .= "<center><img src=\"re_images/$MyImages[0]\"></center><br>";} 

  • #4
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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?

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Because the path to the image is wrong?

  • #6
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    PHP Code:
    $FirstImage '<img src="thumbnails/{$im_array[0]}" alt="' 
    Single quotes are not parsed for variables.

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

  • #7
    New to the CF scene
    Join Date
    Nov 2007
    Posts
    4
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Thank you!! It works!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •