Jump to content

Nested repeat region, Order history page


lobfredd

Recommended Posts

I am trying to create a order history page.

 

I want it to look something like this:

 

Ordernumber:  12

Products:

              Product 1

              Product 2

              Product 3

              Product 4

Total:      xx

 

Ordernumber:  13

Products: 

              Product 5

              Product 6

Total:      xx

 

and so on.

 

I have a recordset which get the ordernumbers from my database

and i have another recordset which get the products (this recordset has a WHERE clause which is used to get the products associated with its ordernumber.

 

    mysql_select_db($database_lol, $lol);
    $query_ono = "SELECT DISTINCT ordre.ono FROM ordre WHERE ordre.bruker='{$_SESSION['MM_Username']}'";
    $ono = mysql_query($query_ono, $lol) or die(mysql_error());
    $row_ono = mysql_fetch_assoc($ono);
    $totalRows_ono = mysql_num_rows($ono);
    
    mysql_select_db($database_lol, $lol);
    $query_history = "SELECT ordre.vare FROM ordre WHERE ordre.ono='{$row_ono['ono']}'";
    $history = mysql_query($query_history, $lol) or die(mysql_error());
    $row_history = mysql_fetch_assoc($history);
    $totalRows_history = mysql_num_rows($history);

 

This is the recordsets.

 

this is my table:

 

+-------+---------------------+------+

| ID      | vare                  | ono  |

+-------+---------------------+------+

|      1 | Product 1          |  12 |

|      2 | Product 2          |  12 |

|      3 | Product 3          |  12 |

|      4 | Product 4          |  12 |

|      5 | Product 5          |  13 |

|      6 | Product 6          |  13 |

+-------+---------------------+------+

 

 

So my question is: How do i do this? list all the records i mean.

Thanks

Link to comment
Share on other sites

You only want ONE query. You will then check for changes in the order number when processing the results and output the necessary content. You show a total in your example output but did not provide the field name that this would come from. So, I used a field called 'cost' in the query. Modify it as needed

 

    mysql_select_db($database_lol, $lol);

    $query = "SELECT ordre.ono, ordre.vare, order.cost
              FROM ordre
              WHERE ordre.bruker='{$_SESSION['MM_Username']}'
              ORDER BY ono";
    $result = mysql_query($query_ono, $lol) or die(mysql_error());
    $current_order_no = false
    while($row = mysql_fetch_assoc($result))
    {
        //Check if this is a new order
        if($current_order_no !== $row['ono'])
        {
            if($current_order_no !== false)
            {
                //Display previous total
                echo "Total: {$total}<br><br>\n";
            }
            $total = 0;
            $current_order_no = $row['ono'];
            echo "Ordernumber:  {$row['ono']}<br>\n"; 
            echo "Products:<br>\n";
        }
        echo "    {$row['ono']}<br>\n";
        $total += $row['cost'];
    }

Link to comment
Share on other sites

DW states that there is a syntax error on this line

 

There's nothing wrong with that line of php code.

 

DW has never been very server-side code aware and frankly, you should not be dependent on your programming editor for the actual php syntax.

 

What sort of problem did you get when you RAN that php code on your server?

Link to comment
Share on other sites

Could you explain a little more please? im not very into coding yet.

 

 while($row = mysql_fetch_assoc($result))

 

DW states that there is a syntax error on this line.

 

Many times syntax errors occur on some line before the reported error. It is just the line that the parser can no longer continue that it shows the line number. In this case the actual error was on the immediately preceding line where I forgot to end with a semi-colon. None of the code I provided is difficult/advanced. It is pretty basic logic. If you want more information I would ask tat you put some time into trying to understand it then ask specific questions about what you don't understand.

Link to comment
Share on other sites

Thanks, works great now!

 

However, the last record's total is not displayed at all  :confused:

 

Here is a pic:

total.png

 

it is always the last one, if i sort it the other way then it is still til one at the bottom.

 

EDIT: just noticed that if there is only one record, then the total is gone too.

 

Any suggestions?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.