Jump to content

Archived

This topic is now archived and is closed to further replies.

DarkHavn

mysql search + php question

Recommended Posts

Hey i was just wondering, i'm building a search engine type script.

I was wondering, i have just build a section of the page, where users can upload an image, descriptions about the image etc and they have a section to enter keywords for that image.

Say up to 200 odd keywords per image.

Now i have a seperate page, the search page, so if someone searched for the word  "Watch" it would search through the keyword section of the database for the word "watch" and bring back the proper results.

My question is, would i use "SELECT * FROM" or is there a proper method if searching the database just for one word, when there is another 199 words with it also?

If you get my drift?

please anyone?

Share this post


Link to post
Share on other sites
Your database should look something like this
[pre]
image            keyword
----------      -----------
imageID    ----< imageID
image_desc      keyword[/pre]

So you might have this in the image table
[pre]
imageID  |  image_desc
---------|---------------------------
  1    |  Moonrise over Yosemite
  2    |  My family  [/pre]
 
and in the keyword table
[pre]
imageID  |  keyword
---------|-----------------
  1    |  moonrise
  1    |  landscape
  1    |  yosemite
  1    |  ansel
  1    |  adams
  2    |  family
  2    |  personal
  2    |  people  [/pre]
 
So if you want to search for images with keyword "landscape"
[code]<?php
$search = "landscape";
$sql = "SELECT i.imageID, i.image_desc
        FROM image i INNER JOIN keyword k ON i.imageID = k.imageID
        WHERE k.keyword = '$search' ";
?>[/code]

Share this post


Link to post
Share on other sites

×

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.