Alpesh Panchal
Alpesh Panchal

Reputation: 53

While loop is repeating one record?

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); 

Upvotes: 1

Views: 163

Answers (1)

Robby Cornelissen
Robby Cornelissen

Reputation: 97120

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.

Upvotes: 1

Related Questions