scriptjet Posted February 5, 2011 Share Posted February 5, 2011 <?php $result = mysql_query ("SELECT genre FROM genres ORDER BY genre"); while ($row = mysql_fetch_row($result)) { echo "<tr>"; for ($i =0; $i<5; i++) { foreach ($row as $genre) echo "<td><input type='submit' name='listMovies' value='" .$genre ."'></td>"; } echo "</tr>"; } ?> ok i'm getting a single line of submit buttons for this output. i want there to be 5 buttons in a row. it seems like i have done this before with the for loop i have, but something is not working right. i know it will have to be a for loop, i just can't figure out where to start it. i know there are 1000 different ways to get the buttons on the screen, but i want to do it with the submit buttons. the best i can get is 5 columns of the same thing i'm outputting now. thanks in advance, i know this is a no-brainer. i just don't have a brain atm Link to comment https://forums.phpfreaks.com/topic/226761-i-know-this-is-another-stupid-question-but-im-tired-and-cant-find-it/ Share on other sites More sharing options...
requinix Posted February 5, 2011 Share Posted February 5, 2011 It's not quite a no-brainer. The basic approach: $column = 1; define("COLUMNS", 5); while ($row = mysql_fetch_row($result)) { if ($column == 1) echo ""; echo ""; $column++; if ($column > COLUMNS) { echo ""; $column = 1; } } // finish off the last row in the table if ($column > 1 && $column while ($column++ "; echo ""; } FYI generally you won't get answers with your code done for you, but I needed that to help me stay awake a bit longer. (As for whether I should be awake at all...) Link to comment https://forums.phpfreaks.com/topic/226761-i-know-this-is-another-stupid-question-but-im-tired-and-cant-find-it/#findComment-1170164 Share on other sites More sharing options...
fortnox007 Posted February 5, 2011 Share Posted February 5, 2011 <?php $result = mysql_query ("SELECT genre FROM genres ORDER BY genre"); while ($row = mysql_fetch_row($result)) { echo "<tr>"; for ($i =0; $i<5; i++) { foreach ($row as $genre) echo "<td><input type='submit' name='listMovies' value='" .$genre ."'></td>"; } echo "</tr>"; } ?> ok i'm getting a single line of submit buttons for this output. i want there to be 5 buttons in a row. it seems like i have done this before with the for loop i have, but something is not working right. i know it will have to be a for loop, i just can't figure out where to start it. i know there are 1000 different ways to get the buttons on the screen, but i want to do it with the submit buttons. the best i can get is 5 columns of the same thing i'm outputting now. thanks in advance, i know this is a no-brainer. i just don't have a brain atm i assume you have <table> before this php code and </table> after it? Link to comment https://forums.phpfreaks.com/topic/226761-i-know-this-is-another-stupid-question-but-im-tired-and-cant-find-it/#findComment-1170177 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.