Jump to content

Image search box


rajeevthomas

Recommended Posts

Hi everyone...

I just came across http://www.phpfreaks.com/tutorial/simple-sql-search . And it works for me. But I am making a gallery. If I have a database with images, keywords, captions, how do I create a search box to search for images? Are there any tutorials? is it possible to make changes to this tutorial to bring up just images? Any directions will help...  :)

Link to comment
Share on other sites

are your images stored as files or as binary data in the database?

you can use a similar search which searches through the image data in the database, i.e. keywords, tags, descriptions regarding the images.

 

Mmmm..hope I am saying this right... in the database there are only image information. And the php file pulls the image based on the information. When I look at my database I only see image info not direct links to them. I hope that answers to your question...how do we do the search you have mentioned?

Link to comment
Share on other sites

You should have an image filename stored in the database, in the same row that has the image descriptions, image name, image title and other details.

Then when a user searches for a image, you have a situation like so:

 

1. Set up database so rows store imagename, image description, image title and most importantly FILENAME.

2. You create a HTML search page which posts to a PHP page, with search box input named "imageSearch"

3. The PHP page is set up something like so

if (isset($_POST['imageSearch']))
{
$searchTerm = $_POST['imageSearch'];

$sql = @mysql_query("SELECT imageTitle, description, filename FROM images WHERE imageTitle LIKE '%$searchTerm%' OR description LIKE '%$searchTerm'");

while ($row = mysql_fetch_array($sql))
{
echo "<p><h1>{$row['imageTitle']}</h1><br/>
{$row['description']}<br/>
<img src='imagesFolder/{$row['filename']' />
</p>"
}
}

 

You can modify it if you want it to return thumbnails, links to the photos etc. That is the basic fundamentals though, you would be able to adapt the PHP Freaks tutorial you mentioned earlier to suit your needs also.

Link to comment
Share on other sites

You should have an image filename stored in the database, in the same row that has the image descriptions, image name, image title and other details.

Then when a user searches for a image, you have a situation like so:

 

1. Set up database so rows store imagename, image description, image title and most importantly FILENAME.

2. You create a HTML search page which posts to a PHP page, with search box input named "imageSearch"

3. The PHP page is set up something like so

if (isset($_POST['imageSearch']))
{
$searchTerm = $_POST['imageSearch'];

$sql = @mysql_query("SELECT imageTitle, description, filename FROM images WHERE imageTitle LIKE '%$searchTerm%' OR description LIKE '%$searchTerm'");

while ($row = mysql_fetch_array($sql))
{
echo "<p><h1>{$row['imageTitle']}</h1><br/>
{$row['description']}<br/>
<img src='imagesFolder/{$row['filename']' />
</p>"
}
}

 

You can modify it if you want it to return thumbnails, links to the photos etc. That is the basic fundamentals though, you would be able to adapt the PHP Freaks tutorial you mentioned earlier to suit your needs also.

 

Joel24 thank you very much..! From what you said I am very interested to know how I can modify it to bring links to the photos or photos? Can you gimme some directions Joel?  :)

Link to comment
Share on other sites

you'll have to play around with it yourself, this is the basic fundamentals though you'll need to modify it all to fit your database setup etc.

if (isset($_POST['imageSearch']))
{
$searchTerm = $_POST['imageSearch'];

$sql = @mysql_query("SELECT imageTitle, description, filename FROM images WHERE imageTitle LIKE '%$searchTerm%' OR description LIKE '%$searchTerm%'");

while ($row = mysql_fetch_array($sql))
{
echo "<p><a href='imagesLocation/{$row['imageLocation']}'>{$row['imageTitle']}</a></p>";
}
}

Link to comment
Share on other sites

you'll have to play around with it yourself, this is the basic fundamentals though you'll need to modify it all to fit your database setup etc.

if (isset($_POST['imageSearch']))
{
$searchTerm = $_POST['imageSearch'];

$sql = @mysql_query("SELECT imageTitle, description, filename FROM images WHERE imageTitle LIKE '%$searchTerm%' OR description LIKE '%$searchTerm%'");

while ($row = mysql_fetch_array($sql))
{
echo "<p><a href='imagesLocation/{$row['imageLocation']}'>{$row['imageTitle']}</a></p>";
}
}

 

Thank you for your help and time... you are so kind...    :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.