• 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

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

PHP - installing Xdebug on Mac with XAMPP (Unix File)

Clear javascript source cache laravel 5.8

PDOException SQLSTATE[HY000] [2002] No such file or directory

How to get page number on dompdf PDF when using "view"

Get sql.h error on MacOS 12 (Monterey) sqsrv and pdo_sqsrv drive installation

Insert And Retrieve Data in MySQL with $.post Noob Question

Creating a config file in PHP

phpmyadmin : Depends: php-twig (>= 2.9) but 2.6.2-2 is to be installed. WHAT?

How to execute sql code based on fetch array

how to retrieve the first and last instance of a row in pdo dataset

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

PHP DOTENV unable to load env vars

PHP my timezone is no setting up in PHP.ini File in xampp

Laravel Excel::store file empty after stored

About Contact Privacy policy Terms and conditions