• 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 render html from a @foreach loop in a textarea

WooCommerce - unset "<product> removed notice…" on cart page

Star and Half Star Rating in Laravel

401 Unauthorized only occurring on some pages in Laravel 8

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null

How to delete old images from public folder on update using Laravel

php: command not found Command PhaseScriptExecution failed with a nonzero exit code

Having issue with matching rows in the database using PDO

Insert multidimensional array to codeigniter cart

retrieve data from database using session

codeigniter 4 running error first time with xampp

Where do I need to place a hook for phpunit?

Pages are working fine on localhost but not running on the hosting server

Required field only if another field has a value, must be empty otherwise

how to use extended ASCII instead of unicode in PHP

About Contact Privacy policy Terms and conditions