shcKr- Posted July 25, 2008 Share Posted July 25, 2008 also... i have a problem, i used a UNION so it would search all the tables and now it is picking up all of the items there and not filtering them by what i searched :S Also i need some help on how to make it go into pages, so all the results are not in one huge line and split into pages of 10 or something this is what it is doing : http://bluid.co.uk/new/search.php?search=bed and heres my code: <?php require 'config.php'; mysql_connect ($dbhost, $dbusername, $dbuserpass); mysql_select_db($dbname) or die('Cannot select database'); if(isset($_GET['search'])) { $search = $_GET['search']; } $search = trim($search); $search = preg_replace('/\s+/', ' ', $search); $keywords = explode(" ", $search); $keywords = array_diff($keywords, array("")); if ($search == NULL or $search == '%'){ } else { for ($i=0; $i<count($keywords); $i++) { $query = "SELECT * FROM accessories UNION SELECT * FROM bedroom UNION SELECT * FROM chaises UNION SELECT * FROM contemporary UNION SELECT * FROM dining UNION SELECT * FROM garden UNION SELECT * FROM kids UNION SELECT * FROM lighting UNION SELECT * FROM living UNION SELECT * FROM mirrors " . "WHERE title LIKE '%".$keywords[$i]."%'". " ORDER BY title"; } $result = mysql_query($query) or die(mysql_error()); } if ($search == NULL or $search == '%'){ } else { $count = mysql_num_rows($result); } echo "<html>"; echo "<head>"; echo "<title>Your Title Here</title>"; echo "<link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\" />"; echo "</head>"; echo "<body onLoad=\"self.focus();document.searchform.search.focus()\">"; echo "<h2>Search</h2>"; echo ""; echo "<form name=\"searchform\" method=\"GET\" action=\"index.php?search\">"; echo "<input type=\"text\" name=\"search\" size=\"20\" TABINDEX=\"1\" />"; echo " <input type=\"submit\" value=\"Search\" style=\"border:1px solid #f2f2f2;background-color:#d7d7d7;font-weight:bold;font-family:Tahoma;color:#888888;height:22px;\"/>"; echo "</form><br>"; if ($search == NULL) { } else { echo "<span style=\"text-transform:capitalize\">You searched for "<b><FONT COLOR=\"#198bc7\">"; foreach($keywords as $value) { print "$value"; } echo "</font></span></b>""; } echo ""; echo ""; if ($search == NULL){ echo "<b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br />"; } elseif ($search == '%'){ echo "<b><FONT COLOR=\"red\">Please enter a search parameter to continue.</font></b><br />"; } elseif ($count <= 0){ echo "<b><FONT COLOR=\"red\">Your query returned no results from the database.</font></b><br />"; } else { echo "<center><br><table id=\"search\" bgcolor=\"#\" width=\"100%\">"; echo "<tr>"; echo "<td height=\"30\"><b>SEARCH RESULTS: </b></td>"; echo "</tr>"; $color1 = "#efefef"; $color2 = "#"; $color3 = "#177cb1"; $color4 = "#299cd8"; while($row = mysql_fetch_array($result)) { $row_color = ($row_count % 2) ? $color1 : $color2; $text_color = ($row_count % 2) ? $color4 : $color3; echo "<tr bgcolor=".$row_color." style=\"color:#198bc7;padding:10px\">"; echo "<td style=\"padding:5px;padding-left:20px;color:".$text_color."\"><strong>- ".$row['title']."</strong></td>"; echo "</tr>"; $row_count++; } echo "</table>"; } echo "</body>"; echo "</html>"; if ($search == NULL or $search == '%') { } else { mysql_free_result($result); } ?> Link to comment https://forums.phpfreaks.com/topic/116556-pagination-search-help/ Share on other sites More sharing options...
jonsjava Posted July 25, 2008 Share Posted July 25, 2008 the UNION issue is a mysql issue, not php. Once you get that fixed, I'll give you a simple pagation script that you can pretty much drop in any site. To get MySQL help, I'd reccomend you take the question over to the MySQL Help area. Link to comment https://forums.phpfreaks.com/topic/116556-pagination-search-help/#findComment-599457 Share on other sites More sharing options...
shcKr- Posted July 25, 2008 Author Share Posted July 25, 2008 ok, thanks Link to comment https://forums.phpfreaks.com/topic/116556-pagination-search-help/#findComment-599491 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.