• 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

Sliders in Laravel

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

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

Call to undefined function openssl_decrypt

passwordless LDAP login and get user information using Kerberos ticket in PHP

javascript html popup window

Warning: Unknown: Failed to write session data using user defined save handler. (session.save_path: ) in Unknown on line 0

Adding reCAPTCHA v2 into my PHP file

Transpose multidimensional array and join values with commas

How can I access an array/object?

Laravel PackageManifest.php: Undefined index: name

Accessors (Getter) & Mutators (Setter) On a Pivot Table in Laravel

Laravel Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) on a sub query with "ROW_NUMBER() OVER PARTITION"

How to Create WooCommerce Subscription Product via. REST API?

Filter WooCommerce related products by Polylang language

About Contact Privacy policy Terms and conditions