• 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

Facebook SDK error: Cross-site request forgery validation failed. Required param "state" missing from persistent data

Doctrine 2 mapping referencing unique key

Sentry on Symfony: how to exclude `NotFoundHttpException`

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

Check for PDO Results, If None Display Message, If Yes then Loop Through

Form Validation and Submission to database

How to read laravel_session cookies saved in cookie memory of browser in client side?

PHP's array_map including keys

Laravel Unknown Column 'updated_at'

Get all WooCommerce products within own plugin

Converting array to string and then back in PHP

backup files to google drive using PHP

PHP Startup: Unable to load dynamic library 'openssl' in Ubuntu

How to submit a form when page loads using JavaScript?

Sagepay Error The Vendor failed to provide a RedirectionURL

About Contact Privacy policy Terms and conditions