dsaba Posted April 23, 2007 Share Posted April 23, 2007 hello! normally i am echoing data from my database in a while statement: while ($queryrow = mysql_fetch_array($query)) { echo 'some data'; } It everything in those brackets always echoes the same for each iteration of that loop I wanted to do something like here in the SMF forums that when it shows replies to a topic, every other reply is in a different color background, blue and light blue This means it will echo one kind of data every other time in the loop. How can I do that with a while statement, or perhaps another kind of loop? -thanks Link to comment https://forums.phpfreaks.com/topic/48223-solved-making-something-echo-for-every-other-in-a-loop/ Share on other sites More sharing options...
dsaba Posted April 23, 2007 Author Share Posted April 23, 2007 i guess if I use for() function and make it loop for a cetain $i or times then I could identify the "every other loop" as an odd or even number how could I do that? or perhaps there is a better way to do I'm getting at here? Link to comment https://forums.phpfreaks.com/topic/48223-solved-making-something-echo-for-every-other-in-a-loop/#findComment-235726 Share on other sites More sharing options...
dsaba Posted April 23, 2007 Author Share Posted April 23, 2007 is_odd($number) { return $number % 2 == 1 ? true : false; } i'm using a for loop for every odd i echo something different thats how i'm doing it, if this helps anyone else Link to comment https://forums.phpfreaks.com/topic/48223-solved-making-something-echo-for-every-other-in-a-loop/#findComment-235737 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.