biscuitboy
Technical User
Hiya,
The script below returns all of records stored in a mysql database and displays them in a table. The current table is displayed like the following:
Surname First Name Flat No etc etc etc
-----------------------------------------------------
record1data data data etc etc etc
record2data data data etc etc etc
However I would like to display it like this:
Surname: Record1data
First name: data
flat no: data
etc
etc
Surname: Record2data
First name: data
Flat no: data
etc
etc
Does anyone have any ideas how I can change the existing code so that the table is formed like the above for each record?
Best Regards
Code:
<?php # Scrtipt 6.6 - viewresidents.php
$page_title = 'View Residents';
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT surname, first_name, flat_no, building_name, tel_no, organisations, Disabilities, Reasons FROM Residents ORDER BY surname";
$result = mysql_query ($query); // run the query
$num = mysql_num_rows ($result); // how many users are there
if ($num > 0) { // if it ran ok display the records
echo "<p><big><b> There are currently $num residents registered.</b></big></p>";
echo '<table align="centre"
cellspacing="2" cellpadding="4">
<tr><b><td align="left"><b>Surname</b>
</td><td align="left"><b>First Name</b>
</td><td align="left"><b>Flat No</b>
</td><td align="left"><b>Building Name</b>
</td><td align="left"><b>Tel No</b>
</td><td align="left"><b>Organisations</b>
</td><td align="left"><b>Disabilities</b>
</td><td align="left"><b>Reasons</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
<td align=\"left\">$row[2]</td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else { // if it did not run ok
echo '<p>There are currently no registered residents.</p>';
}
mysql_close(); // close the database connection
?>
The script below returns all of records stored in a mysql database and displays them in a table. The current table is displayed like the following:
Surname First Name Flat No etc etc etc
-----------------------------------------------------
record1data data data etc etc etc
record2data data data etc etc etc
However I would like to display it like this:
Surname: Record1data
First name: data
flat no: data
etc
etc
Surname: Record2data
First name: data
Flat no: data
etc
etc
Does anyone have any ideas how I can change the existing code so that the table is formed like the above for each record?
Best Regards
Code:
<?php # Scrtipt 6.6 - viewresidents.php
$page_title = 'View Residents';
require_once ('connect.php'); // Connect to the db.
//Make the Query
$query = "SELECT surname, first_name, flat_no, building_name, tel_no, organisations, Disabilities, Reasons FROM Residents ORDER BY surname";
$result = mysql_query ($query); // run the query
$num = mysql_num_rows ($result); // how many users are there
if ($num > 0) { // if it ran ok display the records
echo "<p><big><b> There are currently $num residents registered.</b></big></p>";
echo '<table align="centre"
cellspacing="2" cellpadding="4">
<tr><b><td align="left"><b>Surname</b>
</td><td align="left"><b>First Name</b>
</td><td align="left"><b>Flat No</b>
</td><td align="left"><b>Building Name</b>
</td><td align="left"><b>Tel No</b>
</td><td align="left"><b>Organisations</b>
</td><td align="left"><b>Disabilities</b>
</td><td align="left"><b>Reasons</b>
</td></tr>
';
//fetch and print all the records.
while ($row = mysql_fetch_array($result,MYSQL_NUM)) {
echo "<tr><td align=\"left\">" .
stripslashes($row[0]) . "</td>
<td align=\"left\">$row[1]</td>
<td align=\"left\">$row[2]</td>
<td align=\"left\">$row[3]</td>
<td align=\"left\">$row[4]</td>
<td align=\"left\">$row[5]</td>
<td align=\"left\">$row[6]</td>
<td align=\"left\">$row[7]</td>
</tr>\n";
}
echo '</table>';
mysql_free_result ($result); //Free up the resources.
} else { // if it did not run ok
echo '<p>There are currently no registered residents.</p>';
}
mysql_close(); // close the database connection
?>