why data repeated for all records from table when using mysqli_fetch in loop

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maryreejo
    New Member
    • Apr 2020
    • 1

    why data repeated for all records from table when using mysqli_fetch in loop

    i have a php code like
    while($row1 =mysqli_fetch_a ssoc($check1))
    {
    $leadsl=$row1['leadslno'];
    $CheckSql2 = "SELECT * FROM leadservices,se rvices WHERE leadservices.le adslno='$leadsl ' ";
    $check2=mysqli_ query($con,$Che ckSql2);

    while($row2 =mysqli_fetch_a ssoc($check2))
    {
    $output1[] = array("service_ id" => $row2['service_id'],"service_na me" => $row2['service_name']);

    }
    }
    this inside while loop contents are repeated for all records of 1st while loop
    how to solve this problem
  • lewish95
    New Member
    • Mar 2020
    • 33

    #2
    While it is best to avoid logic that results in looping through a result set twice, if necessary you need to reset the result set back to the start:-

    mysqli_data_see k($newsQuery, 0);

    Comment

    Working...