• 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

Laravel 5 session not persisting after user is logged in

PHP: How to solve ob_start() in combination imagepng() issue?

How to display MySQL table using php and edit it in a web browser

PHP each() function replacement

MySQL upgrade causing unexpected results on simple WHERE clauses

Unable to match results of php hash_hmac() and coldfusion hmac()

Laravel 5.2: Unable to locate factory with name [default]

PHP password_verify

Laravel 5.1 how to use {{ old('') }} helper on blade file for radio inputs

Lexik JWT authentication problem "Invalid credentials"

Laravel : How to Create Dropdown to Select FOREIGN KEY from Other Table?

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

Cache clear probem in Larave

How to use React Router with Laravel?

sort() not affecting original array while inside foreach loop

About Contact Privacy policy Terms and conditions