Php 当循环重复一条记录时?

Php 当循环重复一条记录时?,php,mysql,mysqli,while-loop,Php,Mysql,Mysqli,While Loop,我创建了while循环,用于获取与从URL获取的单词匹配的记录。变量正在获取单词,但当循环仅重复一条记录时,不知道为什么?这是我的密码 include_once('dbconnect.php'); $GetChR=isset($_REQUEST['authchar'])?$_REQUEST['authchar']:''; //get the function include_once ('function.php');[![enter image description here][1]][1

我创建了while循环,用于获取与从URL获取的单词匹配的记录。变量正在获取单词,但当循环仅重复一条记录时,不知道为什么?这是我的密码

include_once('dbconnect.php');
$GetChR=isset($_REQUEST['authchar'])?$_REQUEST['authchar']:'';
 //get the function
include_once ('function.php');[![enter image description here][1]][1]
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 25;
$startpoint = ($page * $limit) - $limit;
//to make pagination
  $statement = " table2, table1 WHERE table1.col2 like '%$GetChR%'";
   echo '<div class="records round">';
   //show records
    $query = mysqli_query($con,"SELECT table2.col2 AS a,table1.col2 AS b,   table1.col1 AS c, table1.q_url AS d, table1.tags AS e FROM {$statement} LIMIT   {$startpoint} , {$limit}");
     while ($row = mysqli_fetch_array($query)) 
     {
         $input='';
        //$Authorname =$row['a'];
        $url = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
        $url=explode('/',$url);
        echo '<div class="record round">'; $input .='<a   href="http://localhost/quotes/'.$url[5].'/'.$row['d'].'.html">';
        echo $input .=$row['b'];echo'</a>';echo '</div>';

         // $count++;  
        }
        echo'</div>';

     echo pagination($statement,$limit,$page); 
include_once('dbconnect.php');
$GetChR=isset($_请求['authchar'])?$_请求['authchar']:'';
//获取函数
包括_once('function.php');[![在此处输入图像描述][1][1]
$page=(int)(!isset($_GET[“page”])?1:$_GET[“page”]);
$limit=25;
$startpoint=($page*$limit)-$limit;
//分页
$statement=“table2,table1,其中table1.col2类似于“%$GetChR%”;
回声';
//显示记录
$query=mysqli_query($con,“从{$statement}LIMIT{$startpoint},{$LIMIT}中选择table2.col2作为a,table1.col2作为b,table1.col1作为c,table1.q_url作为d,table1.tags作为e);
while($row=mysqli\u fetch\u数组($query))
{
$input='';
//$Authorname=$row['a'];
$url=“http://$\u服务器[http\u主机]$\u服务器[REQUEST\u URI]”;
$url=分解(“/”,$url);
回显“”;$input.='';回显“”;
//$count++;
}
回声';
回显分页($statement、$limit、$page);

以下是代码的主要问题:

  • 你不能加入你的队伍。没有描述如何链接
    table1
    table2
    的条件或连接语句。结果是不可预测的,但需要查看您的数据以确定这是否是导致重复记录的原因
  • 通过将请求参数直接转储到查询中,您正在创建一个巨大的SQL注入风险。使用事先准备好的语句

  • 在sql中,结果是正确的,但只是在这里没有得到结果。当您尝试使用sql时,是否使用完全相同的查询?没有连接语句或条件?如果你回显你的PHP创建的查询,当直接在数据库上执行时,完全相同的查询会创建正确的结果吗?你能建议我加入查询吗?兄弟,我再试了一次,发现我的查询有错误,你能建议我加入查询吗?我不知道你的表之间的关系。哪些列用作主键和外键?既然您似乎没有使用
    表2
    中的任何数据,为什么不将其删除?还有,我不是你的兄弟。