Jump to content

SQL query that gets users and their orders (users and orders are pre-filtered)


Recommended Posts

Posted

It should return array [user_id => [order_id1, order_id2, ...], ...] where both users and order pages should be initially (but in the same query) filtered based on some PW $users_selector and $orders_selector. Each order page has field $order_user (e.g. it links order and user). How SQL query should look like? After few hours of own experiments I probably need help to combine SQL and PW selectors. Thanks!

Posted

I'm not sure why you'd need sql for that. Sql queries cannot supply you with a datastructure like you suggested it, it can only return data in a tabular structure, so you need to build up the array no matter how you tackle the problem. 

$usersWithOrders = $users->find("orders.count>0");
$orders = $pages->find("template=order");

$byUser = array();
foreach($usersWithOrders as $u){
  $byUser[$u->id] = $orders->find("id=$u->orders");
}
  • Like 2

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...