How to combine textfield with counter variables


<p><strong><strong>Room Availbility</strong></p>
<p>&nbsp; </p>
<td><table width="61&#37;" 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>

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’re not being very clear, but maybe this will put you on the right path.


<?php
$counter = 1;
while($data = mysql_fetch_assoc($result)){
    echo '<input type="text" name="qty', $counter++ , '" id="qty">'; #<input type="text" name="qty1" id="qty">
}
?>

thanks AnthonySterling for replying… :slight_smile:
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>&nbsp; </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>