Jump to content

need some input on how to do this


scriptjet

Recommended Posts

i'm not sure how to ask this question on google, so i'm going to ask for your help.

 

here's the code that i have the question about

 

<form action='findMovie.php' method='post'>
<table>
<?php
$result = mysql_query ("SELECT genre FROM genres ORDER BY genre");
while ($row = mysql_fetch_array($result)) {
$genre = $row['genre'];
echo "<tr><td>" .$genre ."</td><td><input type='hidden' name='" .$genre ."' value='" .$genre ."'><input type='submit' name='listMovies'></td></tr>";
}
?>
</table>
</form> 

 

so i have this form that creates a list of submits from a table that i have created.  the form works perfectly fine (i realize the design is not that great... i'm just going for functionality now)

 

what i need is to turn the value of the hidden field (which is dynamically created by a variable) into a variable in the handler so that I can search my movie table and get the movies by genre. 

 

does this make sense?  and any help is greatly appreciated.  i'm not a great programmer, but i do it in my spare time as a hobby.  so go easy on my coding, it works and that's the most i'm concerned with at the moment. 

 

thanks ahead of time

Link to comment
https://forums.phpfreaks.com/topic/226535-need-some-input-on-how-to-do-this/
Share on other sites

When you submit that form you will get every hidden element submitted, and you won't be able to tell which was selected.  I would do some basic form tutorials first.  There's a number of ways you could do it - a drop-down list, a radio button, or submit buttons which identify which genre was selected.

Instead of a hidden element, why not just assign the value to the button?

 

<form action='findMovie.php' method='post'>
<table>
<?php
$result = mysql_query ("SELECT genre FROM genres ORDER BY genre");
while ($row = mysql_fetch_array($result)) {

$genre = $row['genre'];

echo "<tr><td>" .$genre ."</td><td><input type='submit' name='listMovies' value='" . $genre ."'></td></tr>";
}
?>
</table>
</form> 

 

That way when you click a button, the genre (value of the button) can be read from $_POST['listMovies']

 

 

 

Or like btherl said with a drop down list...

 

<form action='findMovie.php' method='post'>
<select name="listMovies">
<?php
$result = mysql_query ("SELECT genre FROM genres ORDER BY genre");
while ($row = mysql_fetch_array($result)) {

$genre = $row['genre'];

echo "<option value='" .$genre ."'>" . $genre ."</option>";
}
?>
</select>
</form> 

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.