-3

因此,我正在构建一个搜索站点,其中有一个 PHP/mySQL 搜索和一个 javascript“显示每页结果数”的 HTML 选择,它与用户希望的每页数量一起提交,然后刷新搜索页面。不幸的是,当我加载页面时出现三个错误。刚刚if (isset($_POST['select'])){ $total_pages == $_POST['select'];}设置$total_pages = 12它工作正常吗?

  • 注意:您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在第 36 行的 /Users/Me/Sites/mySite/search.php 中的第 1 行的 '' 附近使用正确的语法
  • 警告:mysql_num_rows() 期望参数 1 是资源,布尔值在第 37 行的 /Users/Me/Sites/mySite/search.php 中给出
  • 警告:在第 104 行的 /Users/Me/Sites/mySite/search.php 中除以零

这是代码:

<?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 &quot;$q&quot;</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))

如果您需要更多代码,我会很快为您提供。任何帮助将不胜感激!

4

1 回答 1

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
于 2012-06-05T05:38:51.953 回答