• 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

how to create html table in php

image source not readable

MySQL default time format UTC or GMT?

Why rand() every time I refresh the page?

Laravel update hasMany relationship using saveMany

Make certain characters of a word from string bold

error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

Split comma separated value from table column into rows using mysql?

Inserting Country Selection into MySQL PHP [duplicate]

Printing more than one array using print_r or any other function in php

Error loading MySQLdb Module 'Did you install mysqlclient or MySQL-python?'

laravel automatically deletes server.php on php artisan serve

PHPS source file - 403 Forbidden You don't have permission to access this resource

How to put php code inside opening and closing shortcodes

PHP returning an error message and false

About Contact Privacy policy Terms and conditions