当父订单的值= 1时,php mysql选择订单详细信息

I'd like to calculate total commission in order details when parent order's field payment_status=1, it means if order gets paid, then calculate, otherwise ignore it.

The following code is not working, but for your reference.

$totalCommissionSql = mysql_query("
    SELECT SUM(a.agent_commission) AS total_commission, a.order_id, b.order_id, b.payment_status 
    FROM order_details a, order b
    WHERE a.order_id=b.order_id AND b.payment_status=1
");

$totalCommissionRow = mysql_fetch_assoc($totalCommissionSql); 

$totalCommission = $totalCommissionRow['total_commission'];

i'm not familiar with mysql so looking for help! THANKS !!!

SELECT SUM(a.agent_commission) AS total_commission,
       a.order_id,
       b.order_id,
       b.payment_status
FROM order_details AS a INNER JOIN `order` AS b USING(order_id)
WHERE b.payment_status = 1;

Selecting a.order_id and b.order_id is unnecessary, both have the same value. Mind the keywords like order, you have to treat with care. See more: http://dev.mysql.com/doc/refman/5.7/en/keywords.html