Steve Angelis Posted June 15, 2008 Share Posted June 15, 2008 I am a nooby to functions so here is what I am trying to do. I am getting all the information from a database, easy. I get it to show the data. Easy The problem is I want it to show a max of 9 entries and then go to the next line, but I am stuck. Here is my code. function ribbons9($ribbon_nums) if (mysql_numrows>9) { echo $content['medal_id']; } I got that far then I got stuck as hell. Does anyone have any ideas? All I want is for it to show the medal_id till there are 9 in a row, then go to the next row and show the next 9 etc till there are none left. Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/ Share on other sites More sharing options...
.josh Posted June 15, 2008 Share Posted June 15, 2008 example: $sql = "select medal_id from table"; $result = mysql_query($sql); $x = 0; while ($list = mysql_fetch_assoc($result)) { echo $list['medal_id']; echo (($x % 9) == 0) ? "<br />" : " "; } Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566141 Share on other sites More sharing options...
Steve Angelis Posted June 15, 2008 Author Share Posted June 15, 2008 $ribbon_select = mysql_query('select * from phpbb_medal_user'); $ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error()); $x = 0; while ($list = mysql_fetch_assoc($ribbon_result)) { echo $list['medal_id']; echo (($x % 9) == 0) ? "<br />" : " "; } There is the complete with table and what not. I get this error: Resource id #13 does not make any sence; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #13' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566143 Share on other sites More sharing options...
Stephen Posted June 15, 2008 Share Posted June 15, 2008 Inside the mysql function at the last part you could put "LIMIT 0,9" and that would retrieve rows 1,2,3,4,5,6,7,8,9. And keep doing that. Sample : $_start=0; $_current=0; $_one=mysql_query("SELECT * FROM place"); $_onenum=mysql_num_rows($_one); do { $_two=mysql_query("SELECT * FROM place LIMIT ".$_start.",9"); while($_rows=mysql_fetch_array($_two)) { echo($_rows["row"]); } $_start+=9; $_current+=9; echo("<br /><br />"); } while ($_onenum>$_current); I think that should work, but I didn't test it. There is probably an easier way anyway. Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566145 Share on other sites More sharing options...
.josh Posted June 15, 2008 Share Posted June 15, 2008 $ribbon_select = mysql_query('select * from phpbb_medal_user'); $ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error()); $x = 0; while ($list = mysql_fetch_assoc($ribbon_result)) { echo $list['medal_id']; echo (($x % 9) == 0) ? "<br />" : " "; } There is the complete with table and what not. I get this error: Resource id #13 does not make any sence; You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #13' at line 1 you're trying to run a query on a result source from another query. remove the mysql_query from $ribbon_select, just put it in quotes as a query string: $ribbon_select = 'select * from phpbb_medal_user'; $ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error()); $x = 0; while ($list = mysql_fetch_assoc($ribbon_result)) { echo $list['medal_id']; echo (($x % 9) == 0) ? "<br />" : " "; } Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566150 Share on other sites More sharing options...
.josh Posted June 15, 2008 Share Posted June 15, 2008 oh and I forgot to increment $x : $ribbon_select = 'select * from phpbb_medal_user'; $ribbon_result = mysql_query($ribbon_select) or die("$ribbon_select does not make any sence;<br>" . mysql_error()); $x = 0; while ($list = mysql_fetch_assoc($ribbon_result)) { echo $list['medal_id']; echo (($x % 9) == 0) ? "<br />" : " "; $x++; } Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566151 Share on other sites More sharing options...
Steve Angelis Posted June 15, 2008 Author Share Posted June 15, 2008 That last one worked thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/110344-solved-functions/#findComment-566153 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.