Jump to content

i know this is another stupid question, but i'm tired and can't find it


scriptjet

Recommended Posts

<?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
Share on other sites

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
Share on other sites

<?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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.