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.

<?php
require 'actions/database.php';

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

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

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

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

Thanks a lot for reading 🙂

Answers:

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
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x