所以我正在构建一个搜索网站,其中有一个PHP / mySQL搜索和一个javascript“显示每页的结果数”HTML选择提交的是用户希望的每页数,然后刷新搜索页。不幸的是,当我加载页面时,我遇到了三个错误。将if (isset($_POST['select'])){ $total_pages == $_POST['select'];}
设置为$total_pages = 12
它可以正常工作吗?
以下是代码:
<?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))
如果您需要更多代码,我会尽快为您解答。任何帮助将不胜感激!
答案 0 :(得分:1)
我认为你的代码应该是这样的,
require('config.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;
$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);
//code continuation