• 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

could not find driver Debian SQL Server PHP

Laravel - Browser displays message again when I press back button

Having trouble with PDO queries (Notice: Undefined index)

What is the function of the (new Date()).getTime() in PHP?

Fatal error: [] operator not supported for strings

WordPress Subquery returns more than 1 row on SELECT

PHP | "The requested PHP extension bcmath is missing from your system."

Laravel php artisan serve to mimic HTTPS

how to pass row id in href of a tag in codeigniter controller?

Form repeater send wrong data with last element in Laravel

Elastic Beanstalk with Laravel Envoy

How to solve Duplicate entry '0' for key 'PRIMARY' in Wordpress?

Laravel query builder binding parameters more than once

using random function but it's displaying duplicates

Laravel print last executed SQL query with Query log

About Contact Privacy policy Terms and conditions