hey there,
i've coded this little search script:
<?php
// Get the search variable from URL
$var = @$_GET['q'] ;
$trimmed = trim($var); //trim whitespace from the stored variable
// rows to return
$limit=10;
// check for an empty string and display a message.
if ($trimmed == "")
{
echo "<p>nope</p>";
exit;
}
// check for a search parameter
if (!isset($var))
{
echo "<p>We dont seem to have a search parameter!</p>";
exit;
}
// Build SQL Query
$query = "select * from thing_users where EXAMPLE like \"%$trimmed%\"
order by EXAMPLE"; // EDIT HERE and specify your table and field names for the SQL query
$numresults=mysql_query($query);
$numrows=mysql_num_rows($numresults);
// No result
if ($numrows == 0)
{
echo "<h1>Oops!</h1>";
}
// next determine if s has been passed to script, if not use 0
if (empty($s)) {
$s=0;
}
// get results
$query .= " limit $s,$limit";
$result = mysql_query($query) or die("Couldn't execute query");
// display what the person searched for
echo "bla";
// begin to show results set
// echo "<strong>Results</strong><ul>\n";
$count = 1 + $s ;
// now you can display the results returned
while ($row= mysql_fetch_array($result)) {
$title = $row["ort"];
$benutzer = $row["user"];
$id = $row["id"];
$about = $row["about"];
$age = $row["age"];
$EXAMPLE = $row["EXAMPLE"];
$EXAMPLEzwei = $row["EXAMPLEzwei"];
$EXAMPLEdrei = $row["EXAMPLEdrei"];
$EXAMPLEvier = $row["EXAMPLEvier"];
$EXAMPLEfuenf = $row["EXAMPLEfuenf"];
$EXAMPLEsechs = $row["EXAMPLEsechs"];
$count++ ;
}
$currPage = (($s/$limit) + 1);
//break before paging
echo "</ul>";
?>
now this works, but i want now to make it search through more then one field. for example not only field EXAMPLE i also want EXAMPLEzwei, EXAMPLEdrei, EXAMPLEvier, EXAMPLEfuenf, EXAMPLEsechs in the same table to get searched. how do i do that?
this doesn't work:
// Build SQL Query
$query = "select * from thing_users where EXAMPLE, EXAMPLEzwei, EXAMPLEdrei, EXAMPLEvier, EXAMPLEfuenf, EXAMPLEsechs like \"%$trimmed%\"
order by EXAMPLE"; // EDIT HERE and specify your table and field names for the SQL query
any hints? 🙁