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
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]
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.