• 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

Smarty: undefined extension class 'Smarty_Internal_Method_Get_Template_Vars'

Execute only one time and then wait set period of time before executing again

Laravel You requested 1 items, but there are only 0 items available

how to create html table in php

json_encode turns array into an object

Show rotation of tweets using current day of month

insert multiple rows in a saveall in cakephp

Fatal error: Trait 'LaminasDbAdapterLaminasDbAdapterAdapterInterface' not found in /var/www/vendor/laminas/laminas-db/src/Adapter/Adapter.php

PHP to search within txt file and echo the whole line

Which is faster php date functions or carbon?

SlimExceptionHttpNotFoundException

Filter WooCommerce products with post__in and additional meta queries

How to submit the custom form data in database in WordPress without plugin using ajax?

Inserting Country Selection into MySQL PHP [duplicate]

VB.NET WebRequest with PHP POST

About Contact Privacy policy Terms and conditions