Display Query in HTML mysql

Dear Expert,

can I query and display like attachment?
query.xlsx
arkam chouAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
Yes.  It's easily done with nested iterators as you retrieve the rows from the data set.  This shows the general design pattern.
http://iconoun.com/demo/temp_arkam.php
<?php // demo/temp_arkam.php
/**
 * SEE: http://www.experts-exchange.com/questions/28689202/Display-Query-in-HTML-mysql.html
 */
error_reporting(E_ALL);
echo '<pre>';

// TEST DATA FROM THE POST AT EE
$rows[] = ['country' => 'US',    'state' => 'LA', 'people' => 'Car'];
$rows[] = ['country' => 'US',    'state' => 'LA', 'people' => 'Motor'];
$rows[] = ['country' => 'US',    'state' => 'LA', 'people' => 'Fan'];
$rows[] = ['country' => 'US',    'state' => 'NY', 'people' => 'Apple'];
$rows[] = ['country' => 'US',    'state' => 'NY', 'people' => 'Speaker'];
$rows[] = ['country' => 'US',    'state' => 'NY', 'people' => 'Shoe'];
$rows[] = ['country' => 'US',    'state' => 'NY', 'people' => 'Airplane'];
$rows[] = ['country' => 'Japan', 'state' => 'AB', 'people' => 'house'];
$rows[] = ['country' => 'Japan', 'state' => 'AB', 'people' => 'hotel'];
$rows[] = ['country' => 'Japan', 'state' => 'AB', 'people' => 'Car'];
$rows[] = ['country' => 'Japan', 'state' => 'AC', 'people' => 'Earphone'];
$rows[] = ['country' => 'Japan', 'state' => 'AC', 'people' => 'Pen'];
$rows[] = ['country' => 'Japan', 'state' => 'AC', 'people' => 'Book'];
$rows[] = ['country' => 'Japan', 'state' => 'AC', 'people' => 'School'];

// DOES THE TEST DATA LOOK OK?  YES.
// var_dump($rows);


// CHANGE INDICATORS
$old_country = FALSE;
$old_state   = FALSE;

// PROCESS ROW BY ROW
foreach ($rows as $row)
{
    // CHANGE OF COUNTRY
    if ($old_country != $row['country'])
    {
        echo "<br>Country: " . $row['country'];
        $old_country = $row['country'];
    }

    // CHANGE OF STATE
    if ($old_state != $row['state'])
    {
        echo "<br>\tState: " . $row['state'];
        $old_state = $row['state'];
    }

    // CHANGE OF PEOPLE ASSUMED ON EVERY ROW
    echo "<br>\t\tPeople: " . $row['people'];
}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.