nathanmaxsonadil Posted August 21, 2007 Share Posted August 21, 2007 I have a query to list the top 4 in a mysql table I want to know how to have an if statment to see what row it's echoing for example if(//your echoing row4) { //do something } echo "//normal query"; Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/ Share on other sites More sharing options...
Wuhtzu Posted August 21, 2007 Share Posted August 21, 2007 Do you mean like knowing which row is odd or even - for example to color every 2nd row? Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330214 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 I mean like I have 4 rows I want before the 3rd row to echo something Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330217 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 Do you want to echo the fourth row at all? Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330223 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 yes I just want to make an addition Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330229 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 $i = 0; while($row = mysql_fetch_assoc($result)){ if($i < 3){ // Rows 1 - 3 } $i++; } Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330235 Share on other sites More sharing options...
Wuhtzu Posted August 21, 2007 Share Posted August 21, 2007 Just add a counter to your while loop: <?php $i = 1; while($row = mysql_fetch_array($gettopfour)) if($i = 3) { echo "something before the 3rd row"; } echo $row['something']; $i++; ?> Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330237 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 thanks Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330239 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 You missed a less than sign, Wuhtzu. Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330243 Share on other sites More sharing options...
Wuhtzu Posted August 21, 2007 Share Posted August 21, 2007 Yes it looks like I did, but I actually meant = and not <= at the time... but now I can see I misunderstood him. I thought of "before the 3rd row to echo something" as "to echo something between the 2nd and 3rd row" - but of course (maybe) he want to highlight the 3 highest scores or something like that. Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330249 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 it puts it on everyline before the 4th one now Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330263 Share on other sites More sharing options...
roopurt18 Posted August 21, 2007 Share Posted August 21, 2007 Yes it looks like I did, but I actually meant = and not <= at the time... but now I can see I misunderstood him. A single = would have been even more wrong in this context. it puts it on everyline before the 4th one now <?php $i = 0; while($row = mysql_fetch_assoc($result)){ if($i == 4){ // Rows 1 - 3 } $i++; } ?> Are you just blindly copying and pasting code or are you making any attempt to understand what's happening here? Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330273 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 I ment to echo something between the 2nd and 3rd row Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330277 Share on other sites More sharing options...
Wuhtzu Posted August 21, 2007 Share Posted August 21, 2007 Yes, I forgot a =, it should have been ==. If you mean / meant between 2nd and 3rd row you can use something like my first code, just correct the = to == <?php $i = 1; while($row = mysql_fetch_array($gettopfour)) if($i == 3) { echo 'something before the 3rd row'; } echo $row['something']; $i++; ?> This will echo 'something before the 3rd row' before the third row... Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330286 Share on other sites More sharing options...
nathanmaxsonadil Posted August 21, 2007 Author Share Posted August 21, 2007 thanks Wuhtzu Link to comment https://forums.phpfreaks.com/topic/66029-solved-how-to-check-what-the-number-is/#findComment-330298 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.