pollysal Posted March 14, 2010 Share Posted March 14, 2010 <html> <body> <p> <?php $result = mysql_query("SELECT distinct room_type,room_price from room1 WHERE room_no NOT IN ( SELECT id_room_no FROM reservation1 WHERE datein >='$datein' AND dateout <='$dateout')"); ?> </p> <p><strong><strong>Room Availbility</strong></p> <p> </p> <td><table width="61%" height="64" border="1" cellpadding="0" cellspacing="0" bordercolor="#CC66CC" class="report2"> <tr> <td width="38" bgcolor="#E8E8E8"><div align="center"><strong>BIL</strong></div></td> <td width="190" bgcolor="#E8E8E8"><div align="center"><strong>Room Type </strong></div></td> <td width="218" bgcolor="#E8E8E8"><div align="center"><strong>Room Price </strong></div></td> <td bgcolor="#E8E8E8"><div align="center"><strong>Quantity</strong></div></td> </tr> <?php $counter=1; while ($data = mysql_fetch_array($result)): ?> <tr> <td height="28"><center><?php echo $start + $counter?> </center></td> <td><?php echo $data['room_type']; ?></td> <td><?php echo $data['room_price']; ?></td> <td width="153"><label> <input type="text" name="qty" id="qty"> </label></td> </tr> <?php $counter++; endwhile; ?> </table> <p> <label> <input type="submit" name="submit" id="submit" value="Submit"> </label> <a href="DisplayDetails.php">Next>> </a></p> </body> </html> i'm really stuck here. May i know how can i combine the variables $counter with the textfield so whenever it's looping, the textfield will become text1, text2 , txt3 ? Hopefully someone can help me.. Quote Link to comment https://forums.phpfreaks.com/topic/195203-how-to-combine-textfield-with-counter-variables/ Share on other sites More sharing options...
wildteen88 Posted March 14, 2010 Share Posted March 14, 2010 You'd use <input type="text" name="qty[<?php echo $counter; ?>]" id="qty"> When dealing with form fields that have the same name it is best add square brackets to the end of the name. That way your fields will be submitted as an array. NOTE: Currently your code does have any <form></form> tags. When using input fields they must be wrapped within in form tags. Other nothing will be submitted. Quote Link to comment https://forums.phpfreaks.com/topic/195203-how-to-combine-textfield-with-counter-variables/#findComment-1025952 Share on other sites More sharing options...
pollysal Posted March 15, 2010 Author Share Posted March 15, 2010 thanks wildteen88 for replying.. but still, i have some difficulties here. How can i make when i click the submit button, it will go to the page 'DisplayDetails.php' where on the page it will only display the row where i have insert value in the textfield? here's the current code : <html> <body> <form action="DisplayDetails.php" method="post"> <p> <?php mysql_connect("localhost","root","alifah89"); mysql_select_db("unik"); $datein=$_POST["datein"]; $dateout=$_POST["dateout"]; $result = mysql_query("SELECT distinct room_type,room_price from room1 WHERE room_no NOT IN ( SELECT id_room_no FROM reservation1 WHERE datein >='$datein' AND dateout <='$dateout')"); ?> </p> <p><strong><strong>Room Availbility</strong></p> <p> </p> <td><table width="61%" height="64" border="1" cellpadding="0" cellspacing="0" bordercolor="#CC66CC" class="report2"> <tr> <td width="38" bgcolor="#E8E8E8"><div align="center"><strong>BIL</strong></div></td> <td width="190" bgcolor="#E8E8E8"><div align="center"><strong>Room Type </strong></div></td> <td width="218" bgcolor="#E8E8E8"><div align="center"><strong>Room Price </strong></div></td> <td bgcolor="#E8E8E8"><div align="center"><strong>Quantity</strong></div></td> </tr> <?php $counter=1; while ($data = mysql_fetch_array($result)): ?> <tr> <td height="28"><center><?php echo $start + $counter?> </center></td> <td><?php echo $data['room_type']; ?></td> <td><?php echo $data['room_price']; ?></td> <td width="153"><label> <input type="text" name="qty<?php echo $counter; ?>" id="qty<?php echo $counter; ?>"> </label></td> </tr> <?php $counter++; endwhile; ?> </table> <p> <label> <input type="submit" name="submit" id="submit" value="Submit"> </label> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/195203-how-to-combine-textfield-with-counter-variables/#findComment-1026334 Share on other sites More sharing options...
wildteen88 Posted March 15, 2010 Share Posted March 15, 2010 Name you fields as qty[x] (x being the counter the variable) <input type="text" name="qty[<?php echo $counter; ?>]" id="qty<?php echo $counter; ?>"> Now in details.php you'd use // check that form is submitted if(isset($_POST['submit'])) { // loop through all quantity fields foreach($_POST['qty'] as $quantity) { // only deal with fields that have a numeric value and are greater than zero if(is_numeric($quantity) && $quantity > 0) { echo "You ordered: " . $quantity ."<br />"; } } } Quote Link to comment https://forums.phpfreaks.com/topic/195203-how-to-combine-textfield-with-counter-variables/#findComment-1026541 Share on other sites More sharing options...
pollysal Posted March 20, 2010 Author Share Posted March 20, 2010 thanks wildteen88 for the reply... however, finally i managed to get the output that i wanted after configure it myself.. Quote Link to comment https://forums.phpfreaks.com/topic/195203-how-to-combine-textfield-with-counter-variables/#findComment-1029312 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.