Forum Moderators: coopster
I am trying to create a table using the following code:
<tr><td><?php echo "$atitle1"; ?></td><td><?php echo "$acode1"; ?></td></tr>
However for each alternate tr I would like to be shaded - so you can follow each line.
Firstly how can I do this on the side of php?
and
Is there any way I can do this so if '$atitle4' (for example) doesn't exist then the tr wont be shown on the webpage?
Many thanks for your suggestions :)
echo ('<tr'. $row_class .'><td>'. $atitle1 .'</td><td>'. $acode1 .'</td></tr>');
with $row_class containing only class="odd" or class="even" controlled by a counter in a FOR (or other suitable) loop.
The class would be defined in an external CSS file, setting the shading etc.
You'll need extra logic to define if the row is written or not.
[edited by: g1smd at 8:37 pm (utc) on April 30, 2008]
would that then be simpliar to:
-----
<table>
<tr><td bgcolor=>Description</td><td>Code</td></tr>
<?php echo ('<tr'. $row_class .'><td>'. $atitle1 .'</td><td>'. $acode1 .'</td></tr>');?>
<?php echo ('<tr'. $row_class .'><td>'. $atitle2 .'</td><td>'. $acode2 .'</td></tr>');?>
</table>
----
with the following on the codes.php page:
----
$title1 = "Blah Blah 1";
$acode1 = "Blah Blah 1.2";
$row_class = some kind of code to make odd or even color
----
Or would the $row_class be in the css?
Sorry for my ignorance.