Home » Php » php – How to run loops to get all data from database

php – How to run loops to get all data from database

Posted by: admin February 25, 2020 Leave a comment

Questions:

I am trying to fetch all the Referrer from current user to the first user.
I am confused on how to use loops to get all the referrer names.
Table look like.

enter image description here

<?php 
session_start();
$userid = $_SESSION['userid']; // this is the current user.
require("connect.php");
//---------------------------------------//
$Referrer='';
$query = "SELECT Username, Referrer FROM member_master WHERE Username='$userid' and Side='right'";
$execute=mysqli_query($connection, $query);
if(mysqli_num_rows($execute)>0)
{
    while($row = mysqli_fetch_assoc($execute))
    {
        $Referrer = $row['Referrer'];
        echo $Referrer; // this is the referrer of current user.
    }
}

?>
How to&Answers: