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 Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/ 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] Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138083 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);?> Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138088 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... Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138098 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 Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138139 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] Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138146 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. Link to comment https://forums.phpfreaks.com/topic/30038-hello-again-small-fuction-help/#findComment-138147 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.