• 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

Display a success custom notice after Placing an Order in WooCommerce

How to connect to MSSQL Server with PHP from Ubuntu 18.04?

Yii2: How do I debug console commands?

Display specific shipping method if woocommerce product has specific acf field value

Laravel views are showing from cache on one server but works fine on other server

Sync Records With Default Values in Pivot Tables, Call to undefined method syncWithPivotDefaults()

Sliders in Laravel

Fatal error: Uncaught Error: Call to undefined method mysqli_stmt::fetch_assoc() [duplicate]

Inserting data into SQL Server Db An Invalid direction was specified

XDebug not working in VScode for php debugging

Why getting "Build step 'Execute shell' marked build as failure" error while creating a backup tar for files

Store multiple fields in JSON column (Nova CMS)

How can I easily switch between PHP versions on Mac OSX?

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

Apply filter array/return terms

About Contact Privacy policy Terms and conditions