jsk1gcc Posted January 3, 2011 Share Posted January 3, 2011 Hi I have an index.php with three drop down boxes on, each drop down uses an SQL statement to pull seatNumber from 'seats' each seat number has a UI and a forgein key field called SrideID. I have the buttons on the dorp down boxes going to dd-check.php, here the seat chosen is posted and a simple echo(just testing it works atm) for me to do any queries I also need the SrideID within the dropdown box, i tried adding it within the <option></option> but it only made the drop down duplicate. 1 1 2 2 3 3 ect..... what i would like is for the SrideID field to be included with in the dropdown box but hidden so i can post it to the dd-check.php and then show the time and price of that particular ride. here is the table and the code so far. Thanks for any help. CREATE TABLE `ride` ( `RrideID` tinyint(1) default NULL, `name` varchar(20) default NULL, `time` tinyint(1) default NULL, `price` varchar(4) default NULL ) INSERT INTO `ride` VALUES (1, 'Swinging Ship', 7, '2.50'); INSERT INTO `ride` VALUES (2, 'Roller Coaster', 5, '3.75'); INSERT INTO `ride` VALUES (3, 'Ice Blast', 4, '3.00'); CREATE TABLE `seats` ( `seatID` int( NOT NULL default '0', `SrideID` tinyint(1) default NULL, `seatNumber` int(2) default NULL, PRIMARY KEY (`seatID`) ) INSERT INTO `seats` VALUES (1, 1, 1); INSERT INTO `seats` VALUES (2, 1, 2); INSERT INTO `seats` VALUES (3, 1, 3); INSERT INTO `seats` VALUES (4, 1, 4); INSERT INTO `seats` VALUES (5, 1, 5); INSERT INTO `seats` VALUES (49, 2, 1); INSERT INTO `seats` VALUES (50, 2, 2); INSERT INTO `seats` VALUES (51, 2, 3); INSERT INTO `seats` VALUES (52, 2, 4); INSERT INTO `seats` VALUES (53, 2, 5); INSERT INTO `seats` VALUES (69, 3, 1); INSERT INTO `seats` VALUES (70, 3, 2); INSERT INTO `seats` VALUES (71, 3, 3); INSERT INTO `seats` VALUES (72, 3, 4); INSERT INTO `seats` VALUES (73, 3, 5); code for index.php <table width="200" border="1"> <tr> <h1>Swinging Ship</h1> <?php echo '<form method="post" name="f1" action="dd-check.php">'; $query_s = "SELECT * FROM `seats` WHERE SrideID='1' ORDER BY seatID"; $result = mysql_query($query_s); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> <tr> <h1>Roller Coaster</h1> <?php echo '<form method="post" name="f2" action="dd-check.php">'; $query_r = "SELECT * FROM `seats` WHERE SrideID='2' ORDER BY seatID"; $result = mysql_query($query_r); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> <tr> <h1>Ice Blast</h1> <?php echo '<form method="post" name="f3" action="dd-check.php">'; $query_i = "SELECT * FROM `seats` WHERE SrideID='3' ORDER BY seatID"; $result = mysql_query($query_i); echo"<select name='seatNumber'><option value=''>Select Seat</option>"; while( $row = mysql_fetch_array($result) ) { echo '<option>'.$row['seatNumber'].'</option>'; } echo '</select>'; mysql_free_result( $result ); echo "<input type='submit' value='Submit'>"; echo "</form>"; ?> </tr> </table> code for dd-check.php <?php $result=$_POST['seatNumber']; echo " <p> the seat choosen is : $result <p> "; //TEST PULL ALL QUERY $testPullAll = mysql_query("SELECT * FROM ride"); echo "<table border='1'> <tr> <th>Name</th> <th>Duration</th> <th>Price</th> </tr>"; while($row = mysql_fetch_array($testPullAll)) { echo "<tr>"; echo "<td>" . $row['name'] . "</td>"; echo "<td>" . $row['time'] . "</td>"; echo "<td>" . $row['price'] . "</td>"; echo "</tr>"; } echo "</table>"; ?> the end result will be a query in dd-check.php that says something like if [hidden SrideID = 1] echo 'the name, time and price of the ride' if [hidden SrideID =2 echo name, time and price if number 3 then echo the rest of the row. any help would be great, i've been using trial and error so far (since yesterday afternoon) with no success =( ps sorry for the long post, i wanted to try and explain everything the best i can. =) Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/ Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 given the seat number, can't you derive SrideID without passing it through the form? Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/#findComment-1154177 Share on other sites More sharing options...
jsk1gcc Posted January 3, 2011 Author Share Posted January 3, 2011 The problem is the seatNumber is duplicated so i can't do it that way. the swinging ship has 48 seats, the roller coaster has 20 and the iceblast has 24 so there are 24 rows of the seatNumber being the same. The unique field is the seatID but that is meaningless atm, I need the name and price and time of the ride which is in the table ride. ride has a the unique field of RrideID, I need to match RrideID and SrideID to pull the name, time and price. at the moment the code i have only pulls the seatNumber from seats, I need to pull the SrideID too, so i can match the two fields and pull the data from the table ride. unless i'm missing something silly I can't see how I do it with what i already have. =) Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/#findComment-1154183 Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 if each seat has a unique seatID, you should be able to tie that to SrideID, no? Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/#findComment-1154188 Share on other sites More sharing options...
jsk1gcc Posted January 3, 2011 Author Share Posted January 3, 2011 can you please explain how i might do this, i can't see how. my first inclination is to say no that is not possible because of duplicate data in the seat table, but if you can see something i can't, can you explain it to me =) thanks =) Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/#findComment-1154200 Share on other sites More sharing options...
BlueSkyIS Posted January 3, 2011 Share Posted January 3, 2011 "SELECT `SrideID`FROM seats WHERE `seatID` = $the_selected_seat_id" Quote Link to comment https://forums.phpfreaks.com/topic/223260-dropdown-box-with-two-fields-one-hidden/#findComment-1154265 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.