Hi to everyone,

I have a problem to create search engine, actually i dont have problem to create simple search engine, i have problem to create search, but with multiple criteria. I need search for recipes database.
So, when u put something to search, below u have 6 options to check (fast, cheap, hot, etc.). If u check one or more options, search need to look that in database. For example:
search: cookies
fast checked
cheep checked
So everything that contain (name:cookies), (critera1: fast), (critera2: cheep) need to be displayed

I hope that i explain my problem good, beacuse my english is not so good


First you have to check that all variables data are comes from submitted form and then you have to fire a database query for search.

i know that... just have problem to create code for that, because i am begginer in php

post what your code you have sofar and we go from there

here it is:

include ("include/header.php");

 if(isset($_POST['RecipesType1'])) {
	$rt = "RecipesType1";}
elseif(isset($_POST['RecipesType2'])) {
	$rt = "RecipesType2";}
elseif(isset($_POST['RecipesType3'])) {
	$rt = "RecipesType3";}
elseif(isset($_POST['RecipesType4'])) {
	$rt = "RecipesType4";}
elseif(isset($_POST['RecipesType5'])) {
	$rt = "RecipesType5";}	
elseif(isset($_POST['RecipesType6'])) {
	$rt = "RecipesType6";}
$var = @$_POST['search'] ;
$trim = trim($var);
if (isset($rt)) { $rt3 = " $rt = 1 AND ";} else { $rt3 = "";}

$query = "SELECT * FROM recipes WHERE";
$query .= $rt3;
$query .= "RecipesName LIKE \"%$trim%\" order by RecipesId ";

$result = mysql_query($query); 
$count = mysql_numrows($result);

if ($trim == "")
echo "<p>Molimo, unesite bar jednu rec...</p><br />
"; ?>  <a href="index.php"><?php echo TEXT_BACK; ?></a>
<div id="bottom"><?php include("bottom.php"); ?></div> <?php  


if ($numrows == 0)
echo "<h4>Results</h4>";
echo "<p>Pretraga za: \"\" . $trim . \"\" je vratila 0 razultata</p>";

if (empty($ste))

$result = mysql_query($query);

if($numrows > 1){ $return = "rezultata";}
else{ $return = "rezultat"; }

echo "<p>Pretraga za: \"" . $var . "&quot je nasla $numrows $return.</p>";

$count = 1 + $ste ;
while ($r= mysql_fetch_array($result))
$id = $sea["RecipesId"];
$name = $sea["RecipesName"];

$count++ ;
echo "<a href=\"recipes_info.php?rec=" . $id . "\">" . $name ."</a>";

sorry for confusing coding, still learning...

your code works only if the recipes can be of only one type

remove line 7 to 24

$var = @$_POST['search'] ;
$trim = trim($var);
$query = "SELECT * FROM recipes WHERE";
     $query .= "RecipesType1=1 AND ";
     $query .= "RecipesType2=1 AND ";
// ....
$query .= "RecipesName LIKE \"%$trim%\" order by RecipesId ";

thx pzuurveen,
this allmost solve my problem, but if i checked RecipesType1 and RecipesType2 in search and for example put word 'cookies' who have values RecipesType1=1 and RecipesType2=0 in database search return me zero result, i want that search return everything with word cookies even RecipesType2=0... I hope u understand me well

Is't that excely what you want?
Does't it mean that your 'cookies' are not of RecipesType2 and therefore should be not returned as result if you check RecipesType2?
Else you neat to explane the var-type and posible values of RecipesType2 in your DB

Don't trust user input, always use mysql_real_escape_string() on user input.

cossay: thx for advice

pzuurveen: I want, because i think is not good if doesnt return any data if two options is checked, and data have value 1 just for first option...
good example is piratebay.org, if u have time u can see what i mean when u put something to searh and check for example video, then try again and check audio and video, it will return same data as when u check only video.

My bad, I asumed that you had a form with checkboxes.
If a checkbox is not cheched it will not be in $_POST
There for if(issset()) is good enough.
if you need also check it value you can simpliy use an &&.
You still need to use isset() or you get an notice if it doen't exist

$trim = mysql_real_escape_string(trim($var));

if(isset($_POST['RecipesType1']) && $_POST['RecipesType1']==1 )
$query .= "RecipesType1=1 AND ";

mysql_real_escape_string($_POST) is not necessary because you don't use the value in the query

Thank you very much for help, this is solved my problem

sorry i didnt answer sooner...