Joshua F Posted January 15, 2011 Share Posted January 15, 2011 I have a log system that allows 10 logs on each side(Left and right). I am trying to make it so that the left side has the 10 most recent logs, then the right as the next 10. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/ Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 Where is the data coming from? Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159903 Share on other sites More sharing options...
Joshua F Posted January 15, 2011 Author Share Posted January 15, 2011 A database. Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159905 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 If you're just trying to get two columns of 10 results each, have a look at this post, otherwise if you're wanting to echo 10 results, echo other data, then echo 10 more results, you can either use an array, or two queries with the appropriate LIMIT clauses. Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159907 Share on other sites More sharing options...
Joshua F Posted January 15, 2011 Author Share Posted January 15, 2011 If you're just trying to get two columns of 10 results each, have a look at this post, otherwise if you're wanting to echo 10 results, echo other data, then echo 10 more results, you can either use an array, or two queries with the appropriate LIMIT clauses. So, if I want to echo 10 results, then go to the next column and echo 10 more I'd use that thread you linked to? Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159913 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 Well, I guess it really depends. If it absolutely has to be like this, then no, the link isn't what you need. 111 212 313 414 515 616 717 818 919 1020 If this will work, then you can do this with the info in that link. 12 34 56 78 910 1112 1314 1516 1718 1920 Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159924 Share on other sites More sharing options...
Joshua F Posted January 15, 2011 Author Share Posted January 15, 2011 Yea, it would have to be like this. 111 212 313 414 515 616 717 818 919 1020 Also, the columns use Accordions to display the info, and the one on the left uses "RAAccordion", and the right one uses "FAAccordion". Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159926 Share on other sites More sharing options...
Pikachu2000 Posted January 15, 2011 Share Posted January 15, 2011 I have no idea what the accordions are. Are they javascript/JQuery/whatever? Anyhow, the get the information from the database, you'd build the query string as normal, and store the results in arrays. For simplicity, I'll assume there will be one field, 'name', returned from each record. This is how I'd do it, but this may give you an idea for another way to do it yourself. Once the values are in arrays, you can manipulate them however you need to. Note that I didn't take into account any error handling, or what to do if there are less than 20 results returned. $query = 'SELECT `name` FROM `table` LIMIT 20'; $result = mysql_query( $query ); $i = 1; // initialize a counter and two empty arrays. $right_array = array(); $left_array = array(); while( $row = mysql_fetch_assoc($result) ) { if( $i < 11 ) { // if $i one of the first ten results, it belongs in left column $left_array[] = $row['name']; } else { // if it ain't in the first ten results, it goes in the right column . . . $right_array[] = $row['name']; } $i++; } Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159934 Share on other sites More sharing options...
ignace Posted January 15, 2011 Share Posted January 15, 2011 $query = 'SELECT `name` FROM `table` LIMIT 20'; $result = mysql_query( $query ); list($left_array, $right_array) = array_chunk(array_map('mysql_fetch_assoc', array_fill(0, mysql_num_rows($result), $result)), 10); Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1159950 Share on other sites More sharing options...
phpfreak Posted January 16, 2011 Share Posted January 16, 2011 Both great examples Quote Link to comment https://forums.phpfreaks.com/topic/224549-echo-10-then-stop-then-echo-the-next-10/#findComment-1160102 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.