• 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 function breaks wp-admin

SendGrid: Sending an email to multiple recipients without other emails being shown on the "to" field

Debugging Stripe Webhook Event

Need to display only array value in JSON output

Converting alphabet letter to alphabet position in PHP [duplicate]

Why does array_map() with null as callback create an "array of arrays"?

PHP | "The requested PHP extension bcmath is missing from your system."

Symfony - EasyAdmin - Add and remove functions are ignored from AssociationField

PHPExcel export HTML table to xlsx

Transpose and flatten two-dimensional indexed array where rows may not be of equal length

PHP rotate matrix counter-clockwise

how can I set a session variable in Drupal 8 and get it in a php script?

PHP Slim Framework request using withAttribute error

Message: Set sys_temp_dir in your php.ini after installed composer

Laravel Pagination links() not working

About Contact Privacy policy Terms and conditions