drnmslpz42661 2015-08-05 08:20
浏览 21
已采纳

虽然循环重复一个记录?

enter image description here I have created while loop which is used to fetch record matching the word getting from URL. The variable is getting the word but while loop is repeating only one record don't know why? here is my code.

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条回答 默认 最新

  • douren0558 2015-08-05 08:36
    关注

    These are the main issues with your code:

    1. You're not joining your tables. There's no condition or join statement that describes how table1 and table2 are to be linked. Results are unpredictable, but would need to see your data to be sure if this is what causes the repeated record.
    2. You're creating a massive SQL injection risk by dumping a request parameter straight into your query. Use prepared statements instead.
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序