@import "http://lib.zetabin.com/jQuery/facebox/facebox.css";
|
Search System
|
|
Topic Started: Jun 30 2008, 09:14 PM (202 Views)
|
|
Admin
|
Jun 30 2008, 09:14 PM
Post #1
|
|
Administrator
- Posts:
- 303
- Group:
- Admins
- Member
- #1
- Joined:
- Mar 20, 2008
|
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]
|
|
|
| |
|
feartec
|
Jul 17 2008, 11:44 AM
Post #2
|
|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
What do you mean with name ? What must i do with ODER BY ?? pls help.
|
|
|
| |
|
JakkyD
|
Jul 17 2008, 02:45 PM
Post #3
|
|
- Posts:
- 72
- Group:
- Contributor
- Member
- #18
- Joined:
- Apr 29, 2008
|
Change name to username
Admin probably just renamed the row username to name in his database.
|
|
|
| |
|
Admin
|
Jul 17 2008, 06:02 PM
Post #4
|
|
Administrator
- Posts:
- 303
- Group:
- Admins
- Member
- #1
- Joined:
- Mar 20, 2008
|
yea what jakkyD said
|
|
|
| |
|
feartec
|
Jul 17 2008, 07:11 PM
Post #5
|
|
- Posts:
- 194
- Group:
- Contributor
- Member
- #25
- Joined:
- Jul 15, 2008
- Website URL
- http://xileon.freehostia.com/
|
How to add my database to the search or other query's?/
|
|
|
| |
| 1 user reading this topic (1 Guest and 0 Anonymous)
|