sir_arcturua — 2012-11-06T06:43:08-05:00 — #1
I am working in an online website for selling books.
There is a table where the sold books are stored, like this:
id | int - autoincrement
CustomerID (foreing key to table Customers)
BookID (foreign key to table Books)
How can I calculate the total quantity of sold books of each one?
For instance, having 'n' books, how many BookID = 1 to n have been sold (how many of each one)?
Thanks a lot!!!
guido2004 — 2012-11-06T06:55:43-05:00 — #2
, COUNT(*) AS Total
GROUP BY BookID
sir_arcturua — 2012-11-06T08:35:29-05:00 — #3
One last question please. Where are the result stored and how can I read them?
I understand I have to run this query and assign a variable to the result.
Is this result an array, having the totals of each BookID per rows?
Thanks a lot for your answer!!
cpradio — 2012-11-06T08:44:31-05:00 — #4
What language are you using? As that question may be better suited in the appropriate forum. If you are using PHP, are you utilizing PDO, MySQLi, MySQL?
sir_arcturua — 2012-11-06T08:53:17-05:00 — #5
Sorry, I am using PHP and MySQL.
Thanks a lot!
cpradio — 2012-11-06T08:55:54-05:00 — #6
Okay, well then you can utilize several different options.
mysql_ fetch_ array, mysql_ fetch_ assoc, and mysql_fetch_row
All of the above options have examples of how to use them.