John Davidson

php - How can I edit the rows of data in a table using data from a database?

0 comments
Message:


How can I format and style the rows of data in this table where it's displaying my data?


    <table class="table">
<tr bgcolor=" #b366ff">
<th>Game</th>
<th>Date</th>
<th>Score</th>
<th>Venue</th>
</tr>

<?php
$sql = "SELECT * FROM game WHERE username = '{$users}' AND savename = '{$saves}';";
$result = mysqli_query($connection, $sql);
?>
<?php
while ($row = mysqli_fetch_assoc($result)){
echo "<tr>";
echo "<td>".$row['team']."</td>";
echo "<td>".$row['date']."</td>";
echo "<td>".$row['score']."</td>";
echo "<td>".$row['venue']."</td>";
echo "</tr>";
}
?>



My Answer:
To edit the rows of data in the table using data from a database, you can modify the values inside the `while` loop where you are fetching the data from the database. For example, you can add an edit button for each row that allows users to edit the data.

Here is an example of how you can add an edit button to each row:

php
while ($row = mysqli_fetch_assoc($result)){
echo "";
echo "".$row['team']."";
echo "".$row['date']."";
echo "".$row['score']."";
echo "".$row['venue']."";
echo "Edit"; // Edit button with a link to edit.php passing the row id
echo "";
}
?>


To format and style the rows of data in the table, you can use CSS. You can add a class to the table rows and style them using CSS. Here is an example:

html










while ($row = mysqli_fetch_assoc($result)){
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
}
?>
Game Date Score Venue
".$row['team']."".$row['date']."".$row['score']."".$row['venue']."



You can customize the CSS styles according to your preferences to format and style the rows of data in the table.

Rate this post

4 of 5 based on 5698 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us