PHP MySql Fetch multiple data




The video tutorial on how we can fetch multiple rows of mysql table in out php application using while loop.

Original source


11 responses to “PHP MySql Fetch multiple data”

  1. hye i have done my coding, but i want to display from a same username to see their own multiple data, but for now i can only display one data from same username. would you mind to check my coding.

    <?php
    session_start();
    ?>
    <?php

    $servername = "localhost";
    $username = "root";
    $password = "mysql";
    $dbname = "Online";

    //Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    //Check connection
    if (mysqli_connect_error())
    {
    echo "Failed to connect to MySQL: " . mysqli_connect_error();
    }

    $result = mysqli_query($conn, "SELECT * FROM Booking WHERE Username = '{$_SESSION['Username']}'" );
    while($row = mysqli_fetch_array($result))

    {
    $BookingID= $row['BookingID'];
    $UserID= $row['UserID'];
    $Username= $row['Username'];
    $Department= $row['Department'];
    $Room= $row['Room'];
    $StartDate= $row['StartDate'];
    $EndDate= $row['EndDate'];
    $StartTime= $row['StartTime'];
    $EndTime= $row['EndTime'];
    $Reason= $row['Reason'];
    }

    mysqli_close($conn);
    ?>

    <body>
    Booking ID:<? echo $BookingID;?><br>
    User ID:<? echo $UserID;?><br>
    Username:<? echo $Username;?> </b></span><br>
    Department:<? echo $Department;?><br>
    Room:<? echo $Room;?><br>
    Start Date:<? echo $StartDate;?><br>
    End Date:<? echo $EndDate;?><br>
    Start Time:<? echo $StartTime;?><br>
    End Time:<? echo $EndTime;?>

    <br><br>

    Booking ID:<? echo $BookingID;?><br>
    User ID:<? echo $UserID;?><br>
    Username:<? echo $Username;?> </b></span><br>
    Department:<? echo $Department;?><br>
    Room:<? echo $Room;?><br>
    Start Date:<? echo $StartDate;?><br>
    End Date:<? echo $EndDate;?><br>
    Start Time:<? echo $StartTime;?><br>
    End Time:<? echo $EndTime;?>

    </body>

  2. Greetings. I can not seem to get this to work.
    I can confirm that my SQL-database got DATA in it's table by using mysqli_num_rows,
    but the while-loop simply won't perform the action inside the loop body.

    while ($row = mysqli_fetch_array($entries)) {
    echo 'Hello' . $row[2] . 'Bye';
    }

Leave a Reply