Jump to content

new to PHP


Scary

Recommended Posts

I'm a little new to PHP, although I can muddle my way through it OK.  I was hoping for some direction converting the function below to loop through 3 different variables in order when called, e.g. tr1, tr2, tr3.  Any help will be gratefully appreciated. 

 

function cellColor($i, $tdEven = "tdEven", $tdOdd = "tdOdd") {

return ($i%2) ? $tdOdd : $tdEven;

}

 

Happy 2009!

 

 

Link to comment
https://forums.phpfreaks.com/topic/139068-new-to-php/
Share on other sites

This might help get you there.

switch($i % 3){
  case 0: $class = 'one';
    break;
  case 1: $class = 'two';
    break;
  default: $class = 'thr';
    break;
}

 

Example:

<html>
<head>
<style>
td { width: 100px; }
tr.one { background-color: #FF3333; }
tr.two { background-color: #33FF33; }
tr.thr { background-color: #3333FF; }
</style>
</head>
<body>
<table>
<?php
for($i=0; $i < 30; $i++){
switch($i % 3){
  case 0: $class = 'one';
    break;
  case 1: $class = 'two';
    break;
  default: $class = 'thr';
    break;
}

  echo "<tr class='$class'>";
    echo "<td>Testing</td>";
  echo "</tr>";
}
?>
</table>
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/139068-new-to-php/#findComment-727354
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.