So I’m building a search site where there is a PHP/ mySQL search and a javascript “show this number of results per page” HTML select which is submitted with the number per page that the user desires and then refreshes the search page. Unfortunately, when I loaded the page I got three errors. With the if (isset($_POST['select'])){ $total_pages == $_POST['select'];} just set to $total_pages = 12 it works fine?
- Notice: You have an error in your SQL syntax; check the manual that
corresponds to your MySQL server version for the right syntax to use
near ” at line 1 in /Users/Me/Sites/mySite/search.php on line 36 - Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /Users/Me/Sites/mySite/search.php on line 37
- Warning: Division by zero in /Users/Me/Sites/mySite/search.php on line 104
Here is the code:
<?php
$q = mysql_real_escape_string(ucfirst(trim($_REQUEST['searchquery'])));
if (isset($q)){
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;
if (isset($_POST['select'])){ $total_pages == $_POST['select'];} //Here edit the amount per page
$record_start = ($page * $total_pages) - $total_pages;
REQUIRE('config.php');
$result = mysql_query("SELECT * FROM companies WHERE company_name LIKE '%$q%' OR company_description LIKE '%$q%' OR cat1 LIKE '%$q' OR cat2 LIKE '%$q' OR cat3 LIKE '%$q' OR company_phone LIKE '%$q' ORDER by company_name LIMIT $record_start,$total_pages") or trigger_error(mysql_error());
$rows = mysql_num_rows($result);
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM companies"),0);
echo "
<h4>Search for "$q"</h4>
<div class='right'>
<div class='textad1'>
<center>
<form name='form1' method='post'>
Results per Page:
<select name='select' onChange='document.form1.submit()'>
<option value='10'";if($_REQUEST['select'] == 12) {echo "selected='selected'";} echo">12</option>
<option value='15'";if($_REQUEST['select'] == 18) {echo "selected='selected'";} echo">18</option>
<option value='25'";if($_REQUEST['select'] == 32) {echo "selected='selected'";} echo">32</option>
</select>
</form>
</center>
</div>
<div class='divider'></div>
</div>
<div class='left'>
<ul>";
while($row = mysql_fetch_array($result))
If you need any more code, I will quickly get you that. Any help will be greatly appreciated!
I think your code should be like this,