简体   繁体   中英

How can I use the number of rows in no. the fetch data?

How can I use the value of for loop to use at numbering in the result of fetch data from database?

$count = 2

then I want the PRocess Step to have a numbering

Process Step 1

Process Step 2

for($i=1;$i<=$count;$i++){
   echo $i;
   echo "<br>";
}

while($proc = $process->fetch()){?>
    <div class="processLeft form">
        <label>
        Process Step <?php echo $i?>:
        <input type="text" id="aline" value="<?php echo $proc['process_step'];  ?>">
        </label>
    </div>
    <div class="processRight form">
        <label>
        Temperature(°C):
        <input type="text" id="aline" value="<?php echo $proc['temp'] . " " . "Degrees";  ?>">
        </label>    
    </div>
    <br>


<?php }
?>

Increment the variable in your while loop.

$i = 1;
while($proc = $process->fetch()){?>
    <div class="processLeft form">
        <label>
        Process Step <?php echo $i?>:
        <input type="text" id="aline" value="<?php echo $proc['process_step'];  ?>">
        </label>
    </div>
    <div class="processRight form">
        <label>
        Temperature(°C):
        <input type="text" id="aline" value="<?php echo $proc['temp'] . " " . "Degrees";  ?>">
        </label>    
    </div>
    <br>


<?php $i++;
}

i'm not sure about what you want to do ... If i'm guessing right it's just something like this

<?php 
$i=1;
while($proc = $process->fetch()) : ?>
<div class="processLeft form">
    <label>
        Process Step <?php echo $i?>:
        <input type="text" id="aline" value="<?php echo $proc['process_step'];  ?>">
    </label>
</div>
<div class="processRight form">
    <label>
        Temperature(°C):
        <input type="text" id="aline" value="<?php echo $proc['temp'] . " " . "Degrees";  ?>">
    </label>    
</div>
<br/>
<?php $i++; endwhile; ?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM