Hey,
I'm want to display data from my database in a 4x4 table in PHP.
Lets for now say I have a name variable setup called $name and I want to select name from my database and display it in the PHP in a table. My code is as follows:-
<table width="965px">
<tr>
<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("setup") or die(mysql_error());
$query = "SELECT * FROM users";
$recset = mysql_query($query) or die("Error message if query
fails");
if( mysql_num_rows($recset) < 0 )
{
// no records found for query
}
else
{
while($row = mysql_fetch_assoc($recset))
{
?>
<td>
<?php $name = $row['name']; ?>
<?php echo $name; ?>
<p>
</td>
<?php
}
}
?>
</tr>
</table>
- <table width="965px">
- <tr>
- <?php
-
- mysql_connect("localhost", "root", "") or die(mysql_error());
- mysql_select_db("setup") or die(mysql_error());
-
- $query = "SELECT * FROM users";
- $recset = mysql_query($query) or die("Error message if query
- fails");
- if( mysql_num_rows($recset) < 0 )
- {
- // no records found for query
- }
- else
- {
- while($row = mysql_fetch_assoc($recset))
- {
- ?>
- <td>
- <?php $name = $row['name']; ?>
- <?php echo $name; ?>
- <p>
- </td>
- <?php
-
- }
- }
-
- ?>
- </tr>
- </table>
But what I want to do is have 4 records, then break down into a new table row. I understand at the moment that it is displaying a table with one table row and then as many columns as there are records in the database, as long as there is no less than 1 record returned. This currently works.
My problem is though, I want a table with 4 columns and 4 rows displaying information from the database in each of the cells. If there are more than 16 values then I want to be able to allow the data to be split over multiple pages, can someone help with this too please?
Thanks in advance!
James.