Forum Moderators: coopster

Message Too Old, No Replies

Using php echo to create color on cols of table

         

Rightz

7:54 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



Helllllo!

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 :)

g1smd

8:26 pm on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I would use:

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]

Rightz

8:36 pm on Apr 30, 2008 (gmt 0)

10+ Year Member



unfortunately you are talking way over my head so i'm going to have to do some research. unless you could help me out ;)

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.

g1smd

8:43 pm on Apr 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



In the CSS:

tr.even td {backgound-color: #3F3F3F};

tr.odd td {background-color: #BFBFBF};