Page is a not externally linkable
- Code, Content, and Presentation
-- HTML
---- Populating a table using php


rocknbil - 10:11 pm on Dec 23, 2009 (gmt 0)


Welcome aboard garywhite glw, there are many ways to do this. The prevous would never be my preference (sorry chasehx) becasue it switches between "plain output" and PHP with a high frequency, which makes it very hard to debug and follow in large acripts.

create a table a single column, multi-row table to display visitors details.

I'd do something more like this, but will add what a lot of people like - alternate color between rows.

// Define these in your style sheet
$white_bg = 'white-bg'; // i.e., .white-bg { background:#fff; }
$gray_bg = 'gray-bg'; // i.e., .gray-bg { background:#d8d8d8; }
// Note also class "hd": .hd { background:#000; color:#fff; text-align:center; }

$output = NULL;


while($row=mysql_fetch_array($result)){
$thisClass=($thisClass==$gray_bg)?$white_bg:$gray_bg;
$output .= '
<tr>
<td class="' . $thisClass . '">' .
$row['Firstname'] . '<br>' .
'<a href="mailto:' .
$row['email'] . '">' .
$row['email'] . '</a><br>' .
$row['Phone'] . '</td>
</tr>';
}


if ($output) {
echo '
<table align="center">
<tr><td class="hd">Name,Email,Phone</td></tr>' .
$output .
'</table>';
}
else { echo '<p>Oops, no records found.</p>'; }

Typed on the fly, may need some debugging . . .


Thread source:: http://www.webmasterworld.com/html/4048592.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com