Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7248535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T22:09:04+00:00 2026-05-28T22:09:04+00:00

I have an array coming from my database I want to format and display

  • 0

I have an array coming from my database I want to format and display with php

Array ( 
  [customer] => Array ( 
    [customer_id] => 1 
    [firstname] => Mitchell 
    [lastname] => Bray 
    [order_id] => 3 
    [date_added] => 2012-01-17 11:22:30 
    [name] => iPod Shuffle 
    [quantity] => 1 
  ) 
)
Array ( 
  [customer] => Array ( 
    [customer_id] => 1 
    [firstname] => Mitchell 
    [lastname] => Bray 
    [order_id] => 3 
    [date_added] => 2012-01-17 11:22:30 
    [name] => iPod Touch 
    [quantity] => 1 
  ) 
)  
Array ( 
  [customer] => Array ( 
    [customer_id] => 1 
    [firstname] => Mitchell 
    [lastname] => Bray 
    [order_id] => 14 
    [date_added] => 2012-01-25 08:39:54 
    [name] => iPod Touch 
    [quantity] => 2 
  ) 
) 
Array ( 
  [customer] => Array ( 
    [customer_id] => 1 
    [firstname] => Mitchell 
    [lastname] => Bray 
    [order_id] => 14 
    [date_added] => 2012-01-25 08:39:54 
    [name] => HTC Touch HD 
    [quantity] => 3 
  ) 
) 
Array ( 
  [customer] => Array ( 
    [customer_id] => 2 
    [firstname] => M 
    [lastname] => Bray 
    [order_id] => 15 
    [date_added] => 2012-02-02 14:33:45 
    [name] => HTC Touch HD 
    [quantity] => 1 
  ) 
)

I want to display something like:

Mitchell Bray
iPod Shuffle qty 3
iPod Touch qty 3
HTC Touch HD qty 3

M Bray
HTC Touch HD qty 1

added sql query if that helps

$sql =  "
    select c.customer_id, c.firstname, c.lastname, 
           o.order_id, o.date_added, 
           op.name, op.quantity
      from `" . DB_PREFIX . "customer` c
      inner join `" . DB_PREFIX . "order` o on o.customer_id = c.customer_id
      inner join `" . DB_PREFIX . "order_product` op on o.order_id = op.order_id";
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T22:09:05+00:00Added an answer on May 28, 2026 at 10:09 pm

    You should use group by.Modify query like this:

    $sql =  "select c.customer_id, c.firstname, c.lastname, 
                       o.order_id, o.date_added, 
                       op.name, sum(op.quantity)
                from `" . DB_PREFIX . "customer` c
                inner join `" . DB_PREFIX . "order` o on o.customer_id = c.customer_id
                inner join `" . DB_PREFIX . "order_product` op on o.order_id = op.order_id
    group by c.customer_id, op.name
    ";
    

    Check Updated Answer:

    $sql =  "select c.customer_id, c.firstname, c.lastname, op.name, sum(op.quantity)
                    from `" . DB_PREFIX . "customer` c
                    inner join `" . DB_PREFIX . "order_product` op on o.order_id = op.order_id
        group by c.customer_id, op.name
        ";
    

    Update 2:

    $sql =  "select *, sum(quantity)  from (select c.customer_id, c.firstname, c.lastname, op.quantity     from `" . DB_PREFIX . "customer` c
                    inner join `" . DB_PREFIX . "order` o on o.customer_id = c.customer_id
                    inner join `" . DB_PREFIX . "order_product` op on o.order_id = op.order_id
    ) result
        group by result.customer_id, result.name
        ";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 2 arrays - one array is coming from the database, another from
I have some data from database coming out in a loop. Each of these
I have to list several elements that are coming from a database source A
So I have some data that's coming back from a database query, and the
VISUAL C++ Question Hi, I have array of 3 elements and I want to
I am coming from a novice database programmer background, mainly using MS Access for
PHP mysql database I have created a follow on question to this one here
PLATFORM: PHP, mySQL WHAT I HAVE: I have a Database table. Within my application,
I have 3 arrays coming from a webservice... Countries : Consists of Key -
need your help with PHP templating. I'm new to PHP (I'm coming from Perl+Embperl).

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.