0 votes
46 views
in Programming by (120 points)

hi guys hope you are well, i'am still learning and new in php, now i'm on progress develop simple website but i have a problem with array and looping, how to stop looping when all data has been output.

<form method="POST" action="storedata_g6b.php">
    <table class="table">
        <thead class="thead-dark">
            <tr>
                <th class="col-3">id</th>
                <th class="col-7">nama</th>
                <th class="col-3">rank</th>
            </tr>
        </thead>
        <tbody>
        <?php
            $rank_b = 'B';
            $sql = "select t_empeval.id, t_empeval.nama from t_empeval Where t_empeval.grade='$c' and sect=CONCAT('$a','$b') order by t_empeval.v1 desc limit ".$var1.",".$var2."";
            $query = mysqli_query($koneksi, $sql);
            if(!$query)
            {
                die('SQL Error :' . mysqli_error($koneksi));
            }
            $b=0;
            while ($array_b = mysqli_fetch_assoc($query))
            {
                if(mysqli_num_rows($query) > 0)
                {
        ?>
                    <tr>
                        <td><input type="text" name="id_b[<?php echo $b; ?>]" value="<?php echo $array_b['id']; ?>"></td>
                        <td><input type="text" name="nama_b[<?php echo $b; ?>]" value="<?php echo $array_b['nama']; ?>"></td>
                        <td><input type="text" name="rank_b[<?php echo $b; ?>]" value="<?php echo $rank_b; ?>"></td>
                    </tr>
        <?php
                    $b++;
                }
            }
        ?>
            <input type="hidden" name="cotton_b" value="<?php echo $b; ?>" />
        </tbody>
    </table>
    <input type="submit" id="submit" name="submit"/>
</form>

 

in this case amount of data will be display is 2 row.

example : 1 => a 2 => a

then if amount of data has been displayed then will break the loop and start other loop. please englithment me, thanks in advance.

Your answer

Thanks for contributing your answer!
Please be sure to answer the question. Provide details with examples and share your research!
Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.

Not a Member yet?

Ask to Folks Login

My Account

Your feedback is highly appreciated