• 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

WordPress - Dynamically add user ID to the end of a URL

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given [duplicate]

How do I call a php file with axios?

Shopify password update using Shopify API

Symfony there are no commands defined in the "make" namespace

Adding reCAPTCHA v2 into my PHP file

How to install php yaml on CentOs?

Laravel whole batch is cancelled if one Job fails

How to identify whether webp image is static or animated?

How to disable only_full_group_by option in Laravel

Laravel - How to properly generate unique slugs from article titles?

SQL AVG() to 2 decimals

WordPress Subquery returns more than 1 row on SELECT

virtctl works when executed via command line but not from php exec()

find in set in laravel ? example

About Contact Privacy policy Terms and conditions