• 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 print last executed SQL query with Query log

Laravel 8 Multiple Relationships for Factory

GA4 custom event from server side, can someone tell me how i can do the following code in php?

How to make Canonicals with PHP

PHP rotate matrix counter-clockwise

Post Form Data To phpmyadmin Database

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

How to redirect to another page after n seconds in wordpress without using javascript?

Adding hreflang tags automatically in WordPress subdirectory multisite

Fatal error: [] operator not supported for strings

Wordpress 'post_type_link' hides permalink

Nginx disallowing execution of PHP in uploads directory with Magento

Target class controller does not exist - Laravel 8

Laravel unique validation on multiple columns

Woocommerce product attributes with hierarchy like categories

About Contact Privacy policy Terms and conditions