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 5 of 5
  1. #1
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts

    pulling info out of a db to be used as an alt tag which contains ' in it?

    Hi All,

    i am having some validation issues with my code as for some reason when i pull out data from my db to use as an alt tag for my images it doesn't like the data with an ' in it

    here is my code
    PHP Code:
    $itemdata "SELECT * 
        FROM category_data 
        WHERE page_category = 'Entertainment' 
        AND cat_id = '$category_list[$cat_count]' 
        AND subcat_id = '$subcategory_list[$sub_count]'"

                    
        
    $item_query=mysql_query($itemdata);
        
    $num_rows mysql_num_rows($item_query);
            
            if (
    $num_rows == 0){
                echo 
    "No Results Please Go Back And Try Again";
            }
              else {
                   while (
    $row mysql_fetch_array($item_query)){
                
    $short_title preg_replace("/#\d: |\s*\(.*\)|\s*\[.*\]/U"""$row['title']);
                  
    //$title = get_string_between(, ':','[');
                
    print "<div class='item'>
                
                <div class='itemIMG'>
                <img src='{$row['image']}' 
                [COLOR="
    Red"]alt='$short_title' [/COLOR]
                title='$short_title'
                height='100' />
                </div>
                
                <div class='itemTitle'>$short_title</div>
                <div class='itemButton'>
                <img src='images/compare.gif' 
                [COLOR="
    Red"]alt='Compare $short_title Prices'[/COLOR] 
                title='Compare $short_title Prices' /></div>
                
                </div>"
    ;
                        
                 } 
    the code in red is what is causing the problems, ive tried adding stuff to $short_title

    PHP Code:
                $short_title preg_replace("/#\d: |\s*\(.*\)|\s*\[.*\]/U"""$row['title']);
                
    $short_title addslashes($short_title); 
    but this has not worked any ideas?

    thanks
    Luke
    Last edited by LJackson; 05-07-2009 at 05:34 PM.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    $short_title=htmlentities($short_title); 
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    hi mate still shows the same validation errors

    sorry if this is in the wrong forum?
    luke
    Last edited by LJackson; 05-07-2009 at 05:33 PM.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,865
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    You need to enclose all your attribute values in double quotes. You may do it like
    PHP Code:
    print '<div class="item">
                
                <div class="itemIMG">
                <img src="'
    .$row['image'].'"
                alt="'
    .$short_title.'"
                title="'
    .$short_title.'"
                height="100" />
                </div>
                ..................
               '

    Or
    PHP Code:
    print "<div class=\"item\">
                
                <div class=\"itemIMG\">
                <img src=\"{$row['image']}\"
                alt=\"{$short_title}\"
                title=\"{$short_title}\"
                height="
    100" />
                </div>
    ..................
                "

    Or using heredoc
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    LJackson (05-07-2009)

  • #5
    Senior Coder
    Join Date
    Jun 2008
    Location
    Cornwall
    Posts
    2,099
    Thanks
    297
    Thanked 12 Times in 12 Posts
    that worked mate thank you

    Luke


  •  

    Posting Permissions

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