• 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

Hide email address with stars (*)

Make Shipping Method fields Mandatory on Woocommerce checkout page

Merge column values from two arrays to form an indexed array of associative arrays

How to convert the int value to inch in PHP [closed]

how to hide previous markers when new markers added in google map javascript api

google content api for shopping

SQL to convert multiple rows into a single row of variable length

Fatal error: Array callback has to contain indices 0 and 1

Sum column values from multiple arrays

Fatal error: Array callback has to contain indices 0 and 1

Execute only one time and then wait set period of time before executing again

How to set a domain name with php artisan serve

str_replace or preg_replace random number from string

How to get the total hour from starting time to end time in php

How to get AJAX to post on second page?

About Contact Privacy policy Terms and conditions