Jump to content

Recommended Posts

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

 

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.

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>

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 />";
        }
     }
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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