scriptjet Posted February 3, 2011 Share Posted February 3, 2011 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 Quote Link to comment Share on other sites More sharing options...
btherl Posted February 3, 2011 Share Posted February 3, 2011 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. Quote Link to comment Share on other sites More sharing options...
AtomicRax Posted February 3, 2011 Share Posted February 3, 2011 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> Quote Link to comment Share on other sites More sharing options...
scriptjet Posted February 3, 2011 Author Share Posted February 3, 2011 awesome -- i was playing with this stuff for like 16 hours yesterday. i knew the answer would be something simple like that, thanks a million guys Quote Link to comment 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.