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

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...)

<?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?

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.