虽然循环重复一个记录?

时间:2015-08-05 08:20:44

标签: php mysql mysqli while-loop

enter image description here我创建了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); 

1 个答案:

答案 0 :(得分:1)

这些是您的代码的主要问题:

  1. 你没有加入你的牌桌。没有描述table1table2如何链接的条件或连接语句。结果是不可预测的,但需要查看您的数据以确定这是否是导致重复记录的原因。
  2. 通过将请求参数直接转储到查询中,您将产生巨大的SQL注入风险。请改用预备语句。