• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

Mysqli Output to a table

phpmysqlmysqli


PHP Snippet 1:

$requiredRows= 18; 
$rows = $result->num_rows ;
$columns = ceil($rows/$requiredRows);
$i = 0;
while($row = $result->fetch_assoc()) 
    {
    if ($i == 0) {
        echo "<table><tr><td>";
    }
    elseif ($i % $columns) {// <> 0
        echo "</td>\n";
        echo "<td>\n";
    }else{//$i % $columns == 0
        echo "</td>\n";
        echo "</tr>\n";
        echo "<tr>\n";
        echo "<td>\n";
    }
    echo $row['country'];
    $i++;
}

Related Snippets

Show only featured products in Woocommerce shop page

onKeyUp event calculation not working on the following rows from php generated forms except the first one

CodeIgniter extend CI_URI undefined method

How do I loop through an MS SQL database with VB.NET?

MySQL upgrade causing unexpected results on simple WHERE clauses

How to put php code inside opening and closing shortcodes

Add bold text and line break into Laravel Notification Email

Clear javascript source cache laravel 5.8

How to test a php login connected to a mysql db through xampp?

Laravel 5 issue with wherePivot

how to make my own auto increment in php?

PHP sort array of objects by two properties

Laravel Factory not calling callback 'afterCreating'

Detect emoticons in string

Edit XML in HTML form and submit to self

About Contact Privacy policy Terms and conditions