mendoz Posted December 9, 2006 Share Posted December 9, 2006 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 urlhttp://control-pc.co.il/test/?page=product&type=laptop&item=1 Quote Link to comment Share on other sites More sharing options...
utexas_pjm Posted December 9, 2006 Share Posted December 9, 2006 [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] Quote Link to comment Share on other sites More sharing options...
marcus Posted December 9, 2006 Share Posted December 9, 2006 You dont echo functions.Just do <?phpeitan(thenyourcasenumberhere);?> Quote Link to comment Share on other sites More sharing options...
mendoz Posted December 9, 2006 Author Share Posted December 9, 2006 thanks for helping but you didn't understand my point.here is what I wanted:$bully="1" <td class="td1"> $bully="2" $bully="2" <td class="td2"> $bully="1"$bully="1" <td class="td1"> $bully="2" $bully="2" <td class="td2"> $bully="1"and so on... Quote Link to comment Share on other sites More sharing options...
mendoz Posted December 9, 2006 Author Share Posted December 9, 2006 And I thought that this is too easy for you freaks :P Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted December 9, 2006 Share Posted December 9, 2006 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] Quote Link to comment Share on other sites More sharing options...
mendoz Posted December 9, 2006 Author Share Posted December 9, 2006 Thanks man, I'll give it a try. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.