Jump to content


Photo

mysql search + php question


  • Please log in to reply
2 replies to this topic

#1 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 02 September 2006 - 01:00 PM

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?

#2 DarkHavn

DarkHavn
  • Members
  • PipPipPip
  • Advanced Member
  • 69 posts

Posted 02 September 2006 - 01:54 PM

awww come one guys/girls don't be like that :(

#3 Barand

Barand
  • Moderators
  • Sen . ( ile || sei )
  • 18,023 posts

Posted 02 September 2006 - 07:20 PM

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"
<?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' ";
?>

If you are still using mysql_ functions, STOP! Use mysqli_ or PDO. The longer you leave it the more you will have to rewrite.

Donations gratefully received






moon.png

|baaGrid| easy data tables - and more
|baaChart| easy line, column and pie charts




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users