I am stuggling with a SQL query that has been bothering me for the last couple of days. And I'm hoping that you guys can help me!
I am going to create a invoice for a shopping cart. The invoices are saved in two tables. The first table "ordre" have the info about the user, whether the invoice is paid or not and the date, etc.. The second table "ordreelementer" hold all the items that belongs to that invoice.
Here comes my problem. How on earth do I get alle the information needed to print a invoice with details about the customer, and the items he/she purchased? I have tried different SQL JOINS but that didn't work as expected. Any help here would be highly appreciated! I'm coding i PHP and running a MySQL database.
This is my latest SQL statement
$sql = "SELECT ordre.id,
ordre.uid,
ordre.dato,
ordre.status,
ordre.betalt,
ordre.navn,
ordre.adresse,
ordreelementer.oid,
ordreelementer.navn AS elnavn,
SUM(ordreelementer.ant * ordreelementer.stkpris) AS tot
FROM ordre
INNER JOIN ordreelementer
ON ordre.id=ordreelementer.oid
WHERE ordre.uid = ".brukerInfo('id')." AND ordre.id = ".$id."";
All help is highly appreciated!