display several rows of a mysql table via php

I just started php and sql, so this question is probably very silly. I have a database containing nicknames, ids and scores, and I would like to display with php all the nicknames and their corresponding scores, how can I do it ?

So far, I’ve got this but it only displays one pseudo and its score.

require 'actions/database.php';

$getAllInfos = $bdd->query('SELECT pseudo, score FROM users');
$AllInfos = $getAllInfos->fetch();

    <div class="container">
        <h2> scores : </h2>
        <?php echo $AllInfos['pseudo'] ?> : <?php echo $AllInfos['score'] ?>

By the way, here is the creation of my database :

$bdd = new PDO('mysql:host=localhost;dbname=seio;charset=utf8;', 'root', 'root');

Thanks a lot for reading 🙂


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

See: https://www.php.net/manual/en/pdostatement.fetchall.php

Which will give you an array you can loop though.

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x