php - Echo something every 24th iteration -
i have stumbled across issue. have been trying make sure whenever id reaches number based on 24 (24, 48, 72, etc) echo output. have clue on how this?
best wishes,
$mysql_connection = mysqli_query($mysqli, "select * data") or die(mysql_error()); while($bar_data = mysqli_fetch_assoc($mysql_connection)) { ?> <div class="item-wrapper"> <div class="item"> <div class="brand"> <p class="brand-content"><?php echo $bar_data["brand"]; ?></p> </div> <div class="type"> <p class="type-content"><?php echo $bar_data["type"]; ?></p> </div> <div class="data"> <p class="data-content"><?php echo $bar_data["content"]; ?>, <?php echo $bar_data["color"]; ?></p> </div> <div class="price"> <p class="price-content"><?php echo $bar_data["price"]; ?></p> </div> <div class="img"> <?php $generator = new \picqer\barcode\barcodegeneratorpng(); echo '<img src="data:image/png;base64,' . base64_encode($generator->getbarcode($bar_data["barcode"], $generator::type_code_128)) . '">'; ?> </div> </div> </div> <?php // when $bar_data["id"] reaches 24 based echo following: echo '</div><div class="page">'; } } ?>
use modulo arithmetic: http://php.net/manual/en/internals2.opcodes.mod.php
if ($bar_data['id'] % 24 == 0) { } if number on within loop mod 24 == 0 can display appropriate content.
the above code means number in $bar_data['id'] has no remainder when divided 24. values such 24, 48, 72 satisfy condition.
Comments
Post a Comment