• 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 can I create a Download Page with post php method?

generate an Excel file using PHP

Transfer data between JavaScript and PHP through JSON

Can I use a WooCommerce function without any WooCommerce page?

WordPress + Nginx on non-standard port behind AWS ELB results in broken links

How to fix bootstrap multiselect search data using ajax

getting error while enter Command => php artisan route:list

PHP: Print caught exception like Xdebug

Currently Using CodeIgniter Framework i have an Error

Handling expired token in Laravel

SQLSTATE[HY000]: General error: 1 table posts has no column named *

Warning: mysqli_stmt::bind_param(): Number of elements in type definition string doesn't match number of bind variables 11 [closed]

MySQL upgrade causing unexpected results on simple WHERE clauses

Why "Class 'GuzzleHttpClient' not found" even after Installing it in Laravel?

Phpunit partial mock + proxy Entity

About Contact Privacy policy Terms and conditions