Presentation of MySQL results using PHP

Presentation of MySQL results using PHP

Post by StevenMarw » Fri, 12 Sep 2003 08:22:26

I am looking to present the first record returned in a seperate table and
then the rest in alternating colour rows like the screenshot here:

If anyone knows how i would go about this i'd appreciate it.

Presentation of MySQL results using PHP

Post by Michael Fe » Sat, 13 Sep 2003 06:58:15

Depends on how your data is stored in the db (especially the first
paragraphs), how you access it and how you build your sites from that.

Just some ideas:

* Read the first story's headline and first paragraph from the db (how
to do this in detail depends on your environment). Create the table, use
<th> for the first headline (makes sense here, IMHO) and <td> for the
first paragraph, style both with CSS if necessary.

* Read the remaining headlines and print them in alternately colored
rows: Put a class ".colored" (for example) in your stylesheet and set a
background-color for that. Assuming that you have the headlines in an
array (e.g. $headlines) you could print it out like this (not tested):

$colored = false;
foreach ($headlines as $h) {
print '<tr><td';
print ($colored) ? ' class="colored">' : '>';
print "$h</td></tr>\n";
$colored = !$colored;

While running through that loop every second row gets a class="colored".