Welcome Guest [Log In] [Register]
Add Reply
Search System
Topic Started: Jun 30 2008, 09:14 PM (202 Views)
Admin
Administrator
update all the red "name" with different rows in your table user

example : username, email ect....remove or add as needed

search.php

Code:
 

<?

//search variable = data in search box or url
if(isset($_GET['search']))
{
$search = $_GET['search'];
}

//trim whitespace from variable
$search = trim($search);
$search = preg_replace('/\s+/', ' ', $search);

//seperate multiple keywords into array space delimited
$keywords = explode(" ", $search);

//Clean empty arrays so they don't get every row as result
$keywords = array_diff($keywords, array(""));

//Set the MySQL query
if ($search == NULL or $search == '%'){
} else {
for ($i=0; $i<count($keywords); $i++) {
$query = "SELECT * FROM users " .
[color=#ee4a2d]"WHERE name LIKE '%".$keywords[$i]."%'".
" OR name LIKE '%".$keywords[$i]."%'" .
" OR name LIKE '%".$keywords[$i]."%'" .
" OR name LIKE '%".$keywords[$i]."%'" .
" OR name LIKE '%".$keywords[$i]."%'" .
" ORDER BY name";[/color]
}

//Store the results in a variable or die if query fails
$result = mysql_query($query) or die(mysql_error());
}
if ($search == NULL or $search == '%'){
} else {
//Count the rows retrived
$count = mysql_num_rows($result);
}


echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">";
echo "<center>";
echo "<br /><form name=\"searchform\" method=\"GET\" action=\"search.php\">";
echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />";
echo " <input type=\"submit\" value=\"Search\" />";
echo "</form>";
//If search variable is null do nothing, else print it.
if ($search == NULL) {
} else {
echo "You searched for <b><FONT COLOR=\"blue\">";
foreach($keywords as $value) {
print "$value ";
}
echo "</font></b>";
}
echo "<p> </p><br />";
echo "</center>";

//If users doesn't enter anything into search box tell them to.
if ($search == NULL){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>";
} elseif ($search == '%'){
echo "<center><b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br /></center>";
//If no results are returned print it
} elseif ($count <= 0){
echo "<center><b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br /></center>";
//ELSE print the data in a table
} else {
//Table header
echo "<center><table id=\"search\">";
echo "<tr>";
[color=#ee4a2d]echo "<td><b>Results:</b></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";[/color]
echo "<tr>";
echo "</table></center>";

//Colors for alternation of row color on results table
$color1 = "#d5d5d5";
$color2 = "#e5e5e5";
//While there are rows, print it.
while($row = mysql_fetch_array($result))
{
//Row color alternates for each row
$row_color = ($row_count % 2) ? $color1 : $color2;
//table background color = row_color variable
echo "<center><table bgcolor=".$row_color.">";
echo "<tr>";
[color=#ee4a2d]echo "<td>".$row['name']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['name']."</td>";[/color]
echo "</tr>";
echo "<br>";
echo "<br>";
echo "</table></center>";
$row_count++;
//end while
}
//end if
}

if ($search == NULL or $search == '%') {
} else {
//clear memory
mysql_free_result($result);
}
?>


[code]
Offline Profile Quote Post Goto Top
 
feartec

What do you mean with name ? What must i do with ODER BY ?? pls help.
Offline Profile Quote Post Goto Top
 
JakkyD
Member Avatar

Change name to username

Admin probably just renamed the row username to name in his database.
Offline Profile Quote Post Goto Top
 
Admin
Administrator
yea what jakkyD said
Offline Profile Quote Post Goto Top
 
feartec

How to add my database to the search or other query's?/
Offline Profile Quote Post Goto Top
 
1 user reading this topic (1 Guest and 0 Anonymous)
« Previous Topic · Other · Next Topic »
Add Reply