• 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 Sanctum CSRF not authenticating

Woocommerce Checkout - Add conditional field required if one field is filled

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

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

WooCommerce Subscriptions: Remove role on cancelled subscription

Display a success custom notice after Placing an Order in WooCommerce

Converting alphabet letter to alphabet position in PHP [duplicate]

Getting output of MS stored procedure on php call

PHPUnit 7: Failed asserting that exception of type InvalidArgumentException is thrown

PHP contact form configuration [duplicate]

WAMP Virtual Host not working

codeigniter 4 running error first time with xampp

Undefined Array Key error when uploading image on php

Cannot pass null argument when using type hinting

How to set a domain name with php artisan serve

About Contact Privacy policy Terms and conditions