Jump to content

Hello again, small fuction help.


mendoz

Recommended Posts

Hey freaks, long time no see  8)

Anyways...

I have this product table, where each row has a different background color.

Im using this at the moment
<td colspan="2" id="td<?php if ($bully==1) { echo "2"; $bully="2"; } else {$bully="1"; } ?>">
But then it becomes annoying when I try to do more complex stuff.

I tried using functions to accomplish the same thing.
This is just the function all modefied and not working.

[code=php]
<?php function eitan($sbully) {
switch($sbully) {
case 1:
$bully="2";
return $sbully;
break;
case 2:
$bully="1";
return $sbully;
break;
}
} ?>[/code]

<?php echo eitan($bully); ?>

This has to be easy for you guys!

this is the url
http://control-pc.co.il/test/?page=product&type=laptop&item=1
Link to comment
https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/
Share on other sites

[code]
<?php function eitan($sbully) {
switch($sbully) {
case 1:
$bully="2";
return $sbully;
break;
case 2:
$bully="1";
return $sbully;
break;
}
} ?>
[/code]
The code above is the same as this...
[code]
<?php function eitan($sbully) {
  return $sbully;
}
?>
[/code]
I think you want something more like...
[code]
<?php function eitan($sbully) {
switch($sbully) {
case 1:

return "2";
break;
case 2:

return "1";
break;
}
} ?>
[/code]
You could do something like this:

[code]$class = "td1";

foreach ($result as $row) {
$class = ($class == "td1") ? "td2" : "td1";
echo '<td class="' . $class . '">some data</td>';
}[/code]

Or, if your're set on using a function:
[code]function eitan() {
global $bully;
$bully = ($bully == 1) ? 2 : 1;
echo $bully;
}

$bully = 1;

foreach ($result as $row) {
echo '<td class="td' . eitan(). '">some data</td>';
}[/code]

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.