Page 1 of 1

search and display images

Posted: Sat May 03, 2008 10:13 am
by gk23
Hi

I am a PHP novice. I am trying to write a code that searches for a keyword in image database, and prints the images when the image matching the keyword is found..

I am able to implement the basic search function. However, there are 2 things I am not being able to do:
1) my code prints out the image path. How do i make it print the image? i am trying to use img src, but not seeing any output :(

2) my search function runs only for single value. I want it to run for multiple values separated by comma.

my code so far is:

Code: Select all

 
if(!$connect)
        {
        die('Could not connect: ' . mysql_error()); //error message if no connect
        }
 
                     mysql_select_db(); //select the database from the server
 
    $sql = "select img_path_name from key_list WHERE key_one like '%$search_item' || key_two like '%$search_item'|| key_three like '%$search_item'|| key_four like '%$search_item'|| key_five like '%$search_item'|| key_six like '%$search_item'"; 
 
    $result = mysql_query($sql,$connect);
 
    while ($r = mysql_fetch_array($result))
    { 
        //echo "<td>" . "<img src=\"/images/www_images/www_images/" . $r[0] . "\" >" . "</td>";
    } // end while 
 
}
else
{
echo "Search string is empty";
}
 

Re: search and display images

Posted: Sat May 03, 2008 11:11 am
by AXEmonster
after you run the page have you viewed the source of the rendered page to see if the <img> tag and its src attribute is parsing correctly

Re: search and display images

Posted: Sat May 03, 2008 11:25 am
by gk23
AXEmonster wrote:after you run the page have you viewed the source of the rendered page to see if the <img> tag and its src attribute is parsing correctly
I did not that!!
Thanks...I tried it, and found out that my image path was incorrect. I have now corected it, and the images are getting displayed.
However, now I have run into another problem.....

The images are separated in two different folders. However, my path points to one folder. So when the user performs a search, all matching images from one folder (pointed to by the path), are displayed. The images which are in the other path do not display correctly......(the output shows a red cross).

Could me suggest any ideas for solving this problem? Thanks again!

Re: search and display images

Posted: Sat May 03, 2008 12:21 pm
by AXEmonster
why do you have 2 directories for your images

and do you access both directories every time