How To Connect Php Echo With Html Table

418 votes 2 answers how to connect php echo with html table Get the solution ↓↓↓

I want to show mysql data in a html table... php echo shows me the content, but how can I transfer this into the html-table ? I've already added some dummy data manually into the html-table ..

<?php $sql = "SELECT id, Datum, Kunde, Menge, Produkt, Produktversion FROM Aufträge"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "<br> ".$row["id"]. " ". $row["Datum"]. " " . $row["Kunde"] . $row["Produkt"] . $row["Produktversion"] . $row["Menge"] ."<br>"; } } else { echo "00 results"; } $conn->close(); ?> <h1>Bestellungen</h1> <div class="countdown" data-role="countdown" data-days="2"></div> <div class="container" style="padding: 25px 0px;"> <table class="table striped hovered border" data-role="datatable" data-searching="true"> <thead> <tr> <th>id.</th> <th>Datum</th> <th>Kunde</th> <th>Produkt</th> <th>Produktversion</th> <th>Menge</th> </tr> </thead> <tbody> <tr><td>2</td><td>Sonne</td><td>Forellen</td><td>50</td><td>Filet</td><td>50</td></tr> <tr><td>3</td><td>Sonne</td><td>Forellen</td><td>50</td><td>Frisch</td><td>50</td></tr> <tr><td>4</td><td>Sonne</td><td>Forellen</td><td>50</td><td>Lebend</td><td>50</td></tr> </tbody> </table> </div> Copy code Undefined asked 2022-03-25 Write your answer 61 votes

Answer

Solution:

You should iterate inside the table and add the html come in echo

<div class="container" style="padding: 25px 0px;"> <table class="table striped hovered border" data-role="datatable" data-searching="true"> <thead> <tr> <th>id.</th> <th>Datum</th> <th>Kunde</th> <th>Produkt</th> <th>Produktversion</th> <th>Menge</th> </tr> </thead> <tbody> <?php while($row = $result->fetch_assoc()) { echo "<tr> <td>".$row["id"]. "</td> <td>". $row["Datum"]. "</td> <td>". $row["Kunde"] . "</td> <td>". $row["Produkt"] . "</td> <td>". $row["Produktversion"] . "</td> <td>". $row["Menge"] ."</td> </tr>"; } ?> </tbody> </table> </div> Copy code Write your answer 329 votes

Answer

Solution:

Remeber you have to loop each to create rows for the table.

$sql = "SELECT id, Datum, Kunde, Menge, Produkt, Produktversion FROM Aufträge"; $result = $conn->query($sql); if ($result->num_rows > 0) { ?> <table> <thead> <tr> <th>id.</th> <th>Datum</th> <th>Kunde</th> <th>Produkt</th> <th>Produktversion</th> <th>Menge</th> </tr> </thead> <tbody> <?php while($row = $result->fetch_assoc()) { //echo "<br> ".$row["id"]. " ". $row["Datum"]. " " . $row["Kunde"] . $row["Produkt"] . $row["Produktversion"] . $row["Menge"] ."<br>"; ?> <td><?php echo $row["id"]; ?></td> <td><?php echo $row["Datum"] ?></td> <td><?php echo $row["Kunde"]; ?></td> <td>---</td> <td>---</td> <td>---</td> <?php } ?> </tbody> </table> <?php } else { echo "00 results"; } $conn->close(); Copy code

You need to create each and every row inside the while loop.

Write your answer

Share solution ↓

Additional Information:

Date the issue was resolved: 2022-03-25 Link To Source Link To Answer People are also looking for solutions of the problem: uncaught error: call to undefined function mysqli_connect()

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Similar questions

Find the answer in similar questions on our website.

570 php - Save data to two different tables in CakePHP 3 840 php - CDbConnection failed to open the DB connection Yii 445 PHP + SQL - Using SQL Server 'Create To' scripts to create tables through PHP 7 Is this an acceptable way to autoload html pages with php? 427 php,mysql,html - Display SQL query(conjunction) properly in HTML 749 php - Multi-tenancy - Create tables up-front or as needed? 703 Laravel php artisan shows error of JWT 928 html - PHP JSON generation problems 98 Including a html form in a php script 653 php - How to read value from HTML text input?

Từ khóa » Echo Th Php