Jump to content

why while print last row? I need to print all record


Sigmahokies
 Share

Recommended Posts

Hi everyone,

I'm trying to display all record in php from database, there are three rows in phpmyadmin already, but why while won't print three rows? it just printed last row. what did I do wrong? I followed exactly from w3school's instruct, but it is still show last row, not all record.

	$show = "SELECT FirstName, LastName, City, State, TimeZone FROM sampleDB";
        
        $query = mysqli_query($GaryDB, $show);
        
        if(mysqli_num_rows($query)) {
            while($row = mysqli_fetch_assoc($query)) {
                
                $display = "<tr><td>".$row['FirstName']."</td><td>".$row['LastName']."</td><td>".$row['City']."</td><td>".$row['State']."</td><td>".$row['TimeZone']."</td></tr>";
            }
        
        } else {
            $display = "<tr><td>None of record in database</td></tr>";
        }
        mysqli_close($GaryDB);
	

Can you help?

Thanks,

Gary

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...