Guest Posted August 20, 2020 Share Posted August 20, 2020 Hello, I have the problem that only one user is displayed in the table require('connection/db1.php'); // Teilnehmerliste $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); <table class="table"> <thead> <tr> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result['id']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <tr> <th scope="row"><?php echo $result2['name']; ?></th> <td><?php echo $result2['date']; ?></td> </tr> </tbody> </table> Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/ Share on other sites More sharing options...
gw1500se Posted August 20, 2020 Share Posted August 20, 2020 You need to put the output in a loop. Fetch only gets 1 row. Your HTML only outputs 1 row. You need to move the fetch and loop on it where you start a new row. Also, don't use * in your select. List only those columns you will actually use. Since you don't use '$count' you don't need that statement. Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580799 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 How do I put this in a loop and $ count is used somewhere else Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580800 Share on other sites More sharing options...
gw1500se Posted August 20, 2020 Share Posted August 20, 2020 Try reading this. Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580801 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 I haven't worked much with loops so far, so I don't know if this is going in the right direction while ($row = $result2->fetchAll(PDO::FETCH_ASSOC)) { Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580802 Share on other sites More sharing options...
gw1500se Posted August 20, 2020 Share Posted August 20, 2020 Not quite. FetchAll will retrieve all the rows at once. If you want to use it then: $rows = $result2->fetchAll(PDO::FETCH_ASSOC) foreach ($rows as $key=>$value) { . . . Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580803 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 <?php require('connection/db1.php'); // Teilnehmerliste $rows = $result2->fetchAll(PDO::FETCH_ASSOC) foreach ($rows as $key=>$value) { $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); } Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580805 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 @gw1500se when i use the code the error comes that the site cannot process any requests at the moment Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580806 Share on other sites More sharing options...
gw1500se Posted August 20, 2020 Share Posted August 20, 2020 That is not the code I suggested. In any case, that error appears to mean the database or network is down. It is coming from the connection code not the loop after the query. Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580807 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 (edited) 1 hour ago, Endrick said: <?php require('connection/db1.php'); // Teilnehmerliste $rows = $result2->fetchAll(PDO::FETCH_ASSOC) foreach ($rows as $key=>$value) { $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); } What is wrong in my code? Edited August 20, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580809 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 I think that the error mean that something is wrong in the Code Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580811 Share on other sites More sharing options...
gw1500se Posted August 20, 2020 Share Posted August 20, 2020 Post the actual error and line to which it refers. Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580812 Share on other sites More sharing options...
mac_gyver Posted August 20, 2020 Share Posted August 20, 2020 there are three current problems - 1. you are getting a fatal runtime error, due to both where you put the php statements and that one of the statements is using a wrong variable name, but you don't have php's error related settings set up so that php will help you. when learning, developing, and debugging code/query(ies), you need to display all php errors. find the php.ini that php is using and set error_reporting to E_ALL and set display_errors to ON. stop and start your web server to insure that any changes made to the php.ini will take effect. 2. where you put those lines of code is nonsense. you put them before the point where you are executing the sql query. this says you are not even looking at what you are doing. you must be aware of what each line of code is doing and what it is contributing to the overall goal. the first line of code, which is attempting to fetch all the rows of data from the query, should replace the current line of code that's fetching just one row of data. it goes in your program at the point where you are fetching the data from the query, which would be after the point where you are executing the query. the second line of code is the start of the loop. it would go at the point in the html document where you are going to repeat the output for each user. you would 'close' the loop, with a } at the end of the block of html that you are repeating for each user. 3. the first line of code you copied, is using a wrong variable name. copying code is not programming. that's just you acting like a human Optical Character Reader (OCR) program. again, you must actually look at and read what the lines of code are doing. in your code, the $start variable (which is poorly named, use something like $stmt to indicate the variable holds a PDOStatement object), is what you would be calling the ->fetchAll() method on. Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580813 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 https://prnt.sc/u33ihn => translated this means "This page does not work" "Can't process this request at the moment." <?php require('connection/db1.php'); // Teilnehmerliste $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); $rows = $result2->fetchAll(PDO::FETCH_ASSOC) foreach ($rows as $key=>$value) { //fetch $result2 = $start->fetch(); // Zählung der Datensätze $count = $start->rowCount(); } Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580814 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 (edited) <?php require('connection/db1.php'); // Teilnehmerliste $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); //fetch $result2 = $start->fetch(); $rows = $result2->fetchAll(PDO::FETCH_ASSOC) foreach ($rows as $key=>$value) { // Zählung der Datensätze $count = $start->rowCount(); } @gw1500se what am I doing wrong Edited August 20, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580816 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 (edited) $rows = $result2->fetchAll(PDO::FETCH_ASSOC); The semicolon was missing now I get a white screen Edited August 20, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580817 Share on other sites More sharing options...
Guest Posted August 20, 2020 Share Posted August 20, 2020 I get this error Fatal error: Uncaught Error: Call to a member function fetchAll() on array in /var/www/html/test.php:44 Stack trace: #0 {main} thrown in Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580818 Share on other sites More sharing options...
gizmola Posted August 21, 2020 Share Posted August 21, 2020 $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); $rows = $start->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { // Zählung der Datensätze echo "<pre>"; print_r($row); echo "</pre>"; } Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580823 Share on other sites More sharing options...
Guest Posted August 21, 2020 Share Posted August 21, 2020 Everything works now, but I want to do it in cards instead of in a table. There I have the problem that the cards do not line up <section class="no-padding-top"> <?php $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); $rows = $start->fetchAll(PDO::FETCH_ASSOC); foreach ($rows as $row) { echo ' <section class="no-padding-bottom"> <div class="container-fluid"> <div class="row"> <div class="col-lg-4"> <div class="user-block block text-center"> <div class="avatar"><img src="https://d19m59y37dris4.cloudfront.net/dark-admin/1-4-6/img/avatar-1.jpg" alt="..." class="img-fluid"> <div class="order dashbg-2">1st</div> </div><a href="#" class="user-title"> <h3 class="h5">Richard Nevoreski</h3><span>@richardnevo</span></a> <div class="contributions">950 Contributions</div> <div class="details d-flex"> <div class="item"><i class="icon-info"></i><strong>150</strong></div> <div class="item"><i class="fa fa-gg"></i><strong>340</strong></div> <div class="item"><i class="icon-flow-branch"></i><strong>460</strong></div> </div> </div> </div> </div> </section>'; } ?> </section> Quote Link to comment https://forums.phpfreaks.com/topic/311357-problem-with-mysql-data-to-html-table/#findComment-1580826 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.