abrahamgarcia27 Posted December 30, 2011 Share Posted December 30, 2011 i have a table that echos 10 entries what i want to do is once it echos 5 records it starts a new table. I dont know how to go about this. Could you guys guide me the right way. Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/ Share on other sites More sharing options...
frostnet Posted December 30, 2011 Share Posted December 30, 2011 I'm trying to understand what you mean but all I can think of is that you want to echo 5 entries from your table? Isn't that limitable by MySQL itself in your query? SELECT * FROM tablename LIMIT 0, 5 Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302401 Share on other sites More sharing options...
abrahamgarcia27 Posted December 30, 2011 Author Share Posted December 30, 2011 well i dont want to limit to 5 entries i want to echo 10 entries but after the 5 entry it goes to another table So preety much <table id=table 1> echo 'record1' echo 'record1' echo 'record1' echo 'record1' echo 'record1' </table <table id=table 2> echo 'record1' echo 'record1' echo 'record1' echo 'record1' echo 'record1' </table> so preety much after it echos the 5 entries it would go to the other table id Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302404 Share on other sites More sharing options...
AyKay47 Posted December 30, 2011 Share Posted December 30, 2011 i have a table that echos 10 entries what i want to do is once it echos 5 records it starts a new table. I dont know how to go about this. Could you guys guide me the right way. where is the data coming from? Please give us a little more details about the issue, and post relevant code. Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302406 Share on other sites More sharing options...
abrahamgarcia27 Posted December 30, 2011 Author Share Posted December 30, 2011 i am using a zend framework youtube so the data is coming from the youtube function echoVideoList($feed) { echo "<h2 style='text-align:left;font-family:Tahoma, Geneva, sans-serif; color:#999;'>Search Results</h2>"; echo '<table class="videoList">'; echo '<tbody width="100%">'; foreach ($feed as $entry) { $videoId = $entry->getVideoId(); $thumbnailUrl = $entry->mediaGroup->thumbnail[0]->url; $videoTitle = $entry->mediaGroup->title; $videoDescription = $entry->mediaGroup->description; print <<<END <tr onclick="ytvbp.presentVideo('${videoId}')"> <td width="130"><img src="${thumbnailUrl}" height="100px" width="100px" /> <br /> <a href="#">${videoTitle}</a> </td> </tr> END; } echo '</table>'; } Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302413 Share on other sites More sharing options...
AyKay47 Posted December 30, 2011 Share Posted December 30, 2011 Set an incrementing variable in your foreach loop and test it's value with a conditional statement. Place the values 1-5 in one table, when the variable hits 6, create a new table to store the remaining values Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302421 Share on other sites More sharing options...
abrahamgarcia27 Posted December 30, 2011 Author Share Posted December 30, 2011 sorry how would i do this i am really new to php i found this example i tried applying, but i dont think i am going the right track <html> <body> <?php $array = array( 1, 2, 3, 4, 5); foreach( $array as $value ) { if( $value == 3 )continue; echo "Value is $value <br />"; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302433 Share on other sites More sharing options...
Pikachu2000 Posted December 30, 2011 Share Posted December 30, 2011 Here's a basic example, using the modulus operator . . . <?php $values = range(1, 21); echo "<table>\n"; $i = 1; foreach( $values as $v ) { echo "<tr><td>$v</td></tr>\n"; if( $i % 5 === 0 && $v !== end($values) ) { echo "</table>\n<table>\n"; } elseif ( $v === end($values) ) { echo "</table>\n"; } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302442 Share on other sites More sharing options...
abrahamgarcia27 Posted December 30, 2011 Author Share Posted December 30, 2011 thanks pikachu2000 Quote Link to comment https://forums.phpfreaks.com/topic/254055-foreach-help/#findComment-1302696 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.