acook Posted January 31, 2008 Share Posted January 31, 2008 I have an array. I'd like to know if there's any way to limit the results it outputs to 10? Here's the array... $results_array4 = array(); while(odbc_fetch_into($result4, $d)) { $results_array4[$d[1]] = $d[0]; } foreach ($results_array4 as $gp4 => $count4) { echo "<tr><td>$count4</td><td>$gp4</td></tr>"; } I tried throwing something like: $arraycount = count($results_array4); while ($arraycount < 10){ } But it didn't work. Is what I'm trying to do possible? Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/ Share on other sites More sharing options...
The Little Guy Posted January 31, 2008 Share Posted January 31, 2008 <?php while(odbc_fetch_into($result4, $d)){ $results_array4[$d[1]] = $d[0]; if($i == 10){ break; } $i++; } foreach ($results_array4 as $gp4 => $count4) { echo "<tr><td>$count4</td><td>$gp4</td></tr>"; } ?> Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/#findComment-454540 Share on other sites More sharing options...
cooldude832 Posted January 31, 2008 Share Posted January 31, 2008 a while construct has a lot of advantages over a for loop beacuse you can do <?php $i = 0; while($row = odb_fetch() && $i < 50){ #Do some stuff $i++; } ?> that will work if u can't "limit" an odbc query Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/#findComment-454543 Share on other sites More sharing options...
haku Posted January 31, 2008 Share Posted January 31, 2008 for($i = 0; $i < 10; $i++) { echo $results_array4[i]; } Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/#findComment-454544 Share on other sites More sharing options...
acook Posted January 31, 2008 Author Share Posted January 31, 2008 Thanks guys, that did it!! SOLVED! (Man I love this place) Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/#findComment-454546 Share on other sites More sharing options...
cooldude832 Posted January 31, 2008 Share Posted January 31, 2008 just be careful with strucutre on using "break" because it can "break" the wrong thing at time Link to comment https://forums.phpfreaks.com/topic/88748-solved-limit-results-in-an-array/#findComment-454550 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.