New row when limit on row reached with mysqli while php -
so have little row setup mysqli echoing system can paste out information want in little boxes have in row. want 4 columns , should filled (if they're not, filled other boxes). now, when limit reached, want new row started on. in theory should easy.. can't figure out.
can you?
$sql = mysqli_query($con, "select * as_sound left join as_account on as_account.id = as_sound.poster_id "); $counter = 0; $max = 4; echo "<div class='row'>"; if(mysqli_num_rows($sql) > 0){ while (($row = mysqli_fetch_assoc($sql)) , ($counter < $max)){ echo " <div class='column'> <div class='item'> <a class='item-link' href='#'><img src='images/test.jpg' alt='header-image' width='346' ></a> <p class='sound-title'><a class='item-link' href='#'>" . $row['name'] ."</p></a> <table style='width:100%'> <td><a class='item-link' href='#'><p class='sound-desc'>" . $row['short_desc'] ."</p></a></td> <td><a class='item-link' href='#'><div class='item-avatar'><img src='" . $row['avatarimg'] . "' alt='avatar'></a></div> </table> <div class='price'>$" . $row['price'] . "</div> </div> </div>"; $counter++; }} echo "</div>";
keep track of how many things you've output:
$col = 1; while(...) { $col++; if ($col > $col_limit) { ... end previous column ... start new column $col = 0; } ... output column }
Comments
Post a Comment