PHP MySQL Join Total Amount


I have two tables: "orders" and "view"
I have a view.php file which displays the division, name, amount, and member fields.

It pulls everything correctly, except the "amount" field. Each division has multiple orders and it only displays the amount of the first order. How can I display the total of all the amounts of each order by the "division"?

orderid - (primary key)

division - (primary key)

This is the mysql query that I have:

"SELECT view.division, view.members, orders.division,, orders.amount
FROM view, orders
WHERE view.division = orders.division"

This is the field that is suppose to display the amount of the order.

$cellvalue = "";
if ((!isset($_GET["edit_fd1"])) && (!isset($_POST["edit_fd1"]))) {
    $itemvalue = $row[1];
} else {
    $itemvalue = qsrequest("edit_fd1");

    $cellvalue = "<input type=\"text\" class=\"field1\" name=\"edit_fd1\" value=\"" . qsreplace_html_quote(stripslashes($itemvalue)) . "\" size=\"30\"  maxlength=\"24\" >";
    if ($cellvalue == "") {
        $cellvalue = "&nbsp;";
    echo $cellvalue;
Who is Participating?
hernst42Connect With a Mentor Commented:
If you have multiple orders for one division you need to GROUP the values in your SQL for the order. So the SQl looks like:

SELECT view.division, view.members, sum(orders.amount)
FROM view, orders
WHERE view.division = orders.division GROUP BY view.division, view.members

If is not uniquw accross the different oders.amount you can't select it in the same query
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.