我创建了 while 循环,用于获取与从 URL 获取的单词匹配的记录。变量正在获取单词,但 while 循环只重复一条记录不知道为什么?这是我的代码。
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);
最佳答案
这些是您的代码的主要问题:
- 您没有入座。没有条件或连接语句描述如何链接
table1
和table2
。结果无法预测,但需要查看您的数据以确定这是否是导致重复记录的原因。 - 您将请求参数直接转储到您的查询中,这会带来巨大的 SQL 注入(inject)风险。请改用准备好的语句。
关于php - while循环重复一条记录?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31827078/