Php 分页不在下一页显示结果

Php 分页不在下一页显示结果,php,Php,请找人帮忙。我使用下面的代码来过滤和显示效果良好的结果。我的问题是结果没有传递到第二页,因此该页变为空白,没有错误。非常新的,所以欢迎所有的帮助 $num_rec_per_page=2; $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("searchresults") or die("ERROR")

请找人帮忙。我使用下面的代码来过滤和显示效果良好的结果。我的问题是结果没有传递到第二页,因此该页变为空白,没有错误。非常新的,所以欢迎所有的帮助

$num_rec_per_page=2;
$con = mysql_connect("localhost","root","");
if (!$con)
{
    die('Could not connect: ' . mysql_error());
}
mysql_select_db("searchresults") or die("ERROR");

if (!isset($_POST['submit'])) exit();

$vars = array('companyname','location');
$verified = TRUE;
foreach ($vars as $v) {
    if (!isset($_POST[$v]) || empty($_POST[$v])) {
       $verified = FALSE;
    }
}
if (!$verified) {
    echo "Sorry no results found, please enter your search";
    exit();
}

// isset function is also used in checking for the existence of data in $_POST
if (isset($_POST["companyname"]) && $_POST["companyname"] != '') {
    $companyname = mysql_real_escape_string($_POST["companyname"]);
    $companyname = " AND (companyname LIKE '%$companyname%')";
}
if (isset($_POST["location"]) && $_POST["location"] != '') {
    $location = mysql_real_escape_string($_POST["location"]);
    $location = " AND (location LIKE '%$location%')";
}

if (isset($_GET["page"])) { $page  = $_GET["page"]; } else { $page=1; };

$start_from = ($page-1) * $num_rec_per_page;

$sql = "SELECT *  FROM reviewsandtips WHERE member_id > 0". $companyname . $location . "LIMIT $start_from, $num_rec_per_page";

$sql_result = mysql_query($sql) or die (mysql_error());

// now echo the code for the table heading
if (mysql_num_rows($sql_result)>0) {

    while ($row = mysql_fetch_assoc($sql_result)) {

    }

    $sql = "SELECT * FROM reviewsandtips WHERE member_id > 0". $companyname . $location;
    $sql_result = mysql_query($sql); //run the query
    $total_records = mysql_num_rows($sql_result); //count number of records
    $total_pages = ceil($total_records / $num_rec_per_page);

    echo "<a href='codetest.php?page=1'>".'|<'."</a> "; // Goto 1st page

    for ($i=1; $i<=$total_pages; $i++) {
        echo "<a href='codetest.php?page=".$i."'>".$i."</a> ";
    }
    echo "<a href='codetest.php?page=$total_pages'>".'>|'."</a> "; // Goto last page

} else {
    echo '<tr><td colspan="5">No results found.</td></tr>';
}
$num\u rec\u每页=2;
$con=mysql_connect(“本地主机”、“根目录”、“根目录”);
如果(!$con)
{
die('无法连接:'.mysql_error());
}
mysql_选择_数据库(“搜索结果”)或死亡(“错误”);
如果(!isset($_POST['submit'])退出();
$vars=array('companyname','location');
$verified=TRUE;
foreach($VAR为$v){
如果(!isset($_POST[$v])| |为空($_POST[$v])){
$verified=FALSE;
}
}
如果(!$verified){
echo“抱歉,没有找到结果,请输入您的搜索”;
退出();
}
//isset函数还用于检查$\u POST中是否存在数据
如果(isset($\u POST[“companyname”])&&$\u POST[“companyname”]!=“”){
$companyname=mysql\u real\u escape\u字符串($\u POST[“companyname]”);
$companyname=“和(类似于“%$companyname%”的companyname”);
}
如果(isset($\u POST[“location”])&&&$\u POST[“location”]!=“”){
$location=mysql\u real\u escape\u字符串($\u POST[“location”]);
$location=“和(类似于“%$location%”的位置”);
}
if(isset($_GET[“page”]){$page=$_GET[“page”];}else{$page=1;};
$start_from=($page-1)*$num_rec_每页;
$sql=“从成员id>0的Reviews和Tips中选择*”$公司名称$地点。“限制$start\u from,$num\u rec\u每页”;
$sql\u result=mysql\u query($sql)或die(mysql\u error());
//现在回显表标题的代码
如果(mysql\u num\u行($sql\u结果)>0){
而($row=mysql\u fetch\u assoc($sql\u result)){
}
$sql=“从成员id>0的Reviews和Tips中选择*。$companyname.$location;
$sql\u result=mysql\u query($sql);//运行查询
$total_records=mysql_num_rows($sql_result);//统计记录数
$total_pages=ceil($total_records/$num_rec_/页);
回声“;
}
回声“;//转到最后一页
}否则{
回显“未找到结果”;
}

mysql\u real\u escape\u string()
不是防止mysql注入的良药。使用事先准备好的陈述。和。。不要使用mysql库,改用mysqli或PDO。再试一次。谢谢大家提供的信息,我会做出更改,看看我的结果。
mysql\u real\u escape\u string()
不是阻止mysql注入的良方。使用事先准备好的陈述。和。。不要使用mysql库,改用mysqli或PDO。再试一次。谢谢大家提供的信息,我会做出更改,看看我能做到什么。