how to combine textfield with counter variables?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • digituf
    New Member
    • Mar 2010
    • 17

    how to combine textfield with counter variables?

    Code:
    <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>&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">
            <?php input type="text" name="qty".$counter; id="qty" ?>
    		</td>
        </tr>
          <?php
      		$counter++;
      		endwhile;
    		?>
        </table>
      <p>
        <label>
        <input type="submit" name="submit" id="submit" value="Submit">
        </label>
      <a href="DisplayDetails.php">Next&gt;&gt;  </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..
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    Line 29 should look like:

    Code:
    <input type="text" name="qty<?php echo $counter; ?>" id="qty<?php echo $counter; ?>">

    Comment

    • digituf
      New Member
      • Mar 2010
      • 17

      #3
      thanks marcus for the reply..
      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.
      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>

      Comment

      Working...