LPB
LPB

Reputation: 319

How to print out a table from mySQL database inside a html/php page

i am trying to print out this table the table from phpmyadmin to my html/php page as a normal table. this is my coding for the page the page Any help would be appreciated Thanks

Upvotes: 0

Views: 3046

Answers (2)

Aniruddha Chakraborty
Aniruddha Chakraborty

Reputation: 1867

Looks like You were Using PDO , and all of a sudden you jump into old data fetching technique using mysql_*

My advice is to stick with PDO structure . SO you have to some little things

on line 6 use

$stmt->rowCount();

to get user row

then use

$data = $stmt->fetchAll();

to get database rows , You'll get an object .

Now You just need to loop through object for example

foreach ( $data as $rows ){

         echo $rows->users;

   }

Upvotes: 1

lyndact
lyndact

Reputation: 1

Try this code:

<?php 
$db = new mysqli("localhost", "root", "", "hangman");
 ?>

<table border="1">
<tr>
<td>User</td>
<td>Score</td>
</tr>
<tr>
<?php 
    $sql = "SELECT * FROM usernames";
    $result = $db-query($sql);
    while($row = mysqli_fetch_assoc($result)) {
        ?>
        <td><?php echo $row['users']; ?></td>
        <td><?php echo $row['Scores']; ?></td>
        <?php
    }
 ?>
</tr>
</table>

give me a comment if any errors.

Upvotes: 1

Related Questions