Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Duly Noted, apologies. - Duncan.
Overview: A MySQL database has been setup which requests the results from the database, currently the table headings are typed manually.
Problem:
How would I request and display the column heading directly from the database (mySQL)?
Area: See the "// Column Headings" section in the code
Note: Using PHP and PEAR DB.
Any help would be appreciated, many thanks.
- DuncanCode: Select all
<?php
//
// PHP: This queries the database for all properties on the database, and displays the results.
// Includes: Alternating colours for rows on the table.
//
require_once('db_login.php');
$query = ("SELECT *
FROM `properties`
NATURAL JOIN `available`");
$result = $db->query($query);
if(DB::isError($result)) {
die("Could not query the database: <br />".DB::errorMessage($result));
}
$alternateRows=false;
// Table
echo ('<table border="1">'); // Display results in table
echo '<tr class="cellcolor">
// Column Headings
<td>Property<br />Id No
<td>Status<br />(Available)
<td>Property<br />Type
<td>Living<br />Room
<td>Living Room<br />Size
<td>Electric
<td>Gas
<td>Electric or<br />Gas Cooker?
<td>Garden
<td>Broadband<br />Installed
<td>Broadband Company
<td>When<br />Available
<td>Useable
<td>Additional Information<tr>'; //Table Headings
// END OF Column Headings
// While - Display all results
while($myrow = $result->fetchRow()) {
// Alternate Row colours
if($alternateRows==false) { // Alternate Rows for change of colour on row option of true/false.
echo '<tr><td>';
$alternateRows=true;
}
elseif($alternateRows==true) {
echo '<tr class="altrowcolor"><td>'; // altrowcolor class selected here; under "true" for alternateRows.
$alternateRows=false;
}
echo $myrow[1] . '</td><td>'; //
echo $myrow[15] . '</td><td>';
echo $myrow[3] . '</td><td>';
echo $myrow[5] . '</td><td>';
echo $myrow[6] . '</td><td>';
echo $myrow[7] . '</td><td>';
echo $myrow[8] . '</td><td>';
echo $myrow[9] . '</td><td>';
echo $myrow[10] . '</td><td>';
echo $myrow[11] . '</td><td>';
echo $myrow[12] . '</td><td>';
echo $myrow[13] . '</td><td>';
echo $myrow[14] . '</td><td>';
echo $myrow[16] . '</td>';
} // end While statement
echo ('</table>') ; // end Table
$db->disconnect();
?>Weirdan | Please use
Code: Select all
,Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]