I'm stuck.. I'm trying to have a search engine that is uses drop down menu selections.
$all_vars = array("artist","color","size","medium","category"); //sets arrays of what can be found
$x = 0;
for($i = 0; $i < count($all_vars); $i++)
{ // Counts vasriables and makes adjustments - start
if(strlen($_POST[$all_vars[$i]]) > 0)
{ // start - setting user variables
$user_vars[$x][0] = $all_vars[$i];
$user_vars[$x][1] = $_POST[$all_vars[$i]];
$x++;
} //end - setting user variables
} // Counts vasriables and makes adjustments - End
// Defines the query
$poster_sql = "SELECT * FROM poster WHERE ";
for($i = 0; $i < count($user_vars); $i++)
{
if($i != count($user_vars) - 1)
{
$poster_sql = $poster_sql . $user_vars[$i][0] . " = \"" . $user_vars[$i][1] . "\" AND ";
}
else
{
$poster_sql = $poster_sql . $user_vars[$i][0] . " = \"" . $user_vars[$i][1] . "\" ORDER BY code ASC LIMIT $from, $max_results;";
}
}
Now this works wonderfully when searching within 1 category. What I need it to do is have it search in 3 categories. Now I do know it can check into those 3 columns using if else statements.
here is a sameple I used when did using a $_GET[] fuction..
if (isset($_GET['show_cat']))
{
$show_cat = $_GET['show_cat'];
if (mysql_num_rows(mysql_query("Select * FROM $table WHERE category = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'")) > 0)
{
$total_sql = "Select * FROM $table WHERE category = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'";
}
elseif (mysql_num_rows(mysql_query("Select * FROM $table WHERE category2 = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'")) > 0)
{
$total_sql = "Select * FROM $table WHERE category2 = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'";
}
elseif (mysql_num_rows(mysql_query("Select * FROM $table WHERE category3 = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'")) > 0)
{
$total_sql = "Select * FROM $table WHERE category3 = $show_cat AND medium > 'Hand Colored Prints' AND medium > 'Antique Prints'";
}
else
{
include ("../misc/error.php");
exit;
}
}
else
{
$total_sql = "SELECT * FROM $table WHERE medium > 'Hand Colored Prints' AND medium > 'Antique Prints'";
}
Now that works fine but I need that same kind of functionality, but I'm stuck becuase of the array feature being used. So this is as far as I got:
if(isset($_POST['big_search']))
{ // start of big search
if(isset($_POST['category']))
{ // Checks to see if category variable is set - start
$all_vars = array("artist","color","size","medium","category"); //sets arrays of what can be found
$x = 0;
for($i = 0; $i < count($all_vars); $i++)
{ // Counts vasriables and makes adjustments - start
if(strlen($_POST[$all_vars[$i]]) > 0)
{ // start - setting user variables
$user_vars[$x][0] = $all_vars[$i];
$user_vars[$x][1] = $_POST[$all_vars[$i]];
$x++;
} //end - setting user variables
// Defines the query
$sql = "SELECT * FROM poster WHERE ";
for($i = 0; $i < count($user_vars); $i++)
{
if($i != count($user_vars) - 1)
{
$sql = $sql . $user_vars[$i][0] . " = \"" . $user_vars[$i][1] . "\" AND ";
}
else
{
$sql = $sql . $user_vars[$i][0] . " = \"" . $user_vars[$i][1] . "\" ORDER BY code ASC LIMIT $from, $max_results;";
}
}
if (mysql_num_rows(mysql_query($sql)) > 0)
{ // If the query gives a result of this query this it sets the $poster variable
$poster_sql = $sql;
}
???
} // checks ot see if category is set - end
} // Counts vasriables and makes adjustments - End
any help would be awesome thanks.. And sorry for the extremely long post..