Jump to content

mysql search + php question


DarkHavn

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?
Link to comment
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]
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.