Current location: Hot Scripts Forums » Programming Languages » PHP » Search & Queries by Keywords


Search & Queries by Keywords

Reply
  #1 (permalink)  
Old 04-15-07, 01:34 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Search & Queries by Keywords

My girlfriend and her friends wanted to make a small database full of recipies. I got the program FormsToGo, made up a simple form page and everything went great. All recipies are submited to the database with no problems. Well now the entries are really getting way too long to display at once. So I want to make it to where they can search for certain ones by ingredients.

The database is as follows
-Recipies
---Ingredients
---CookingTime
---Difficulty
---Feeds

I need to search by keywords in ingrediants and have an output of just those recipies. Can someone help me out please.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-15-07, 02:37 PM
alej469's Avatar
alej469 alej469 is offline
Newbie Coder
 
Join Date: Apr 2005
Location: West Midlands, UK
Posts: 51
Thanks: 0
Thanked 0 Times in 0 Posts
A simple search query would be:

Code:
$query= "SELECT * FROM Recipies WHERE Ingredients LIKE '%ingredient_name_here%'";

$result=mysql_query($query);
__________________
Funny videos
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-15-07, 04:30 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
This is base of the search code I have now. No php errors but no results are being displayed. The file name is search.php.

PHP Code:

<form action="search.php" method="post">
<INPUT NAME="search" TYPE="text" VALUE="Keywords..." SIZE="33" MAXLENGTH="50">
</form>
<?
    $query
"SELECT * FROM Recipies WHERE Ingredients LIKE 'search'";
    
$result=mysql_query($query);
    while ( 
$row mysql_fetch_array($result) ) {
?>
<tr>
<td><? echo $row['Dish']; ?></td>
<td><? echo $row['Ingredients']; ?></td>
</tr>
<?
  
}
?>

Last edited by Nico; 04-15-07 at 04:45 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-15-07, 04:44 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Try:
PHP Code:

$query"SELECT * FROM Recipies WHERE Ingredients LIKE '%"mysql_real_escape_string($_POST['search']) ."%'"
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-15-07, 05:11 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks that worked perfectly

Last edited by Zaiaku; 04-15-07 at 05:29 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-15-07, 05:30 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Replace this:
PHP Code:

$result=mysql_query($query); 

with this:
PHP Code:

$result=mysql_query($query) OR die( mysql_error() ); 


And are you sure Recipies shouldn't be Recipes?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-15-07, 07:41 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
well it should be but I made a typo setting everything up.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-15-07, 08:10 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Okay... so do you get any errors after the change?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 04-15-07, 09:08 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
No errors what so ever. It works perfectly. Thank you so much. Althought the results are from oldest to newest. Is there a way to make the results list from last added to oldest?

Last edited by Zaiaku; 04-15-07 at 09:11 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 04-16-07, 02:00 PM
Zaiaku Zaiaku is offline
Newbie Coder
 
Join Date: Apr 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Nevermind I got the it ordering perfectly.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SEO Meta Keywords Auto Generator vasasha General Advertisements 1 08-16-05 03:36 PM
SEO Expert Available nakulgoyal Job Offers & Assistance 2 08-14-04 01:38 PM
Simple search script niceguyonline Script Requests 3 03-08-04 12:09 AM
Declared Functions skipper23 PHP 4 12-17-03 11:06 AM
index page not showing up skipper23 PHP 3 12-15-03 02:10 PM


All times are GMT -5. The time now is 12:43 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.