• 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 rotation of tweets using current day of month

WordPress Subquery returns more than 1 row on SELECT

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

WAMP/Wordpress - cURL error 28: Operation timed out after 10001 milliseconds with 0 bytes received

Implode array with array of glue strings

Form Validation and Submission to database

How to update array value in Laravel

Distribute array row data to make multiple new rows

PHP array, move keys and values to new array, but mix it up

Uploading video to Youtube using Youtube Data API V3 and Google API Client PHP -- getting 401 (unauthorized) message

PHP sort array of objects by two properties

If action is on a different page do I use fwrite function

Creating command to backup MySql database in Laravel

PHP Startup Unable to load dynamic library /usr/lib/php/20151012/php_mysqli.dll

How to add a sidebar to Woocommerce Shop Page?

About Contact Privacy policy Terms and conditions