Jump to content

Cinema Profits - SQL Help

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
104 replies to this topic

#1
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Hey guys, can you help me?

Welcome to Stav Cinemas

At the moment, the code is this:

<?php


$result = mysql_query("SELECT (COUNT(bookings.orderID) * prices.priceCost) AS price, customerFirstName, customers.priceID FROM bookings, customers, prices WHERE bookings.custID = customers.customerID AND customers.priceID = prices.priceID GROUP BY bookings.custID, customers.customerID");


while ($row = mysql_fetch_array($result))

{

echo $row["customerFirstName"] . " " . $row["price"] . "<br />";

}


?>

You can see the output in the link.

The number next to each person is how much they have spent on the site in total. Now, how do I total this all up in the SQL query (the while loop will have to go once there's a single piece of data)?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#2
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Anyone at all?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#3
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Mate. I would love to help you but I am still in the process of learning MySQL. But from what I can understand.

Couldn't you store each of the prices in an array, then using a loop add them all together and then print the answer?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#4
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Yes, but that is slow and inefficient. Doing it in the SQL is much faster and cleaner.

Anyone, please?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#5
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
OK well then I can't, sorry mate.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#6
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Dang. :( Winged?
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#7
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
PM him and get him to visit this thread.
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#8
Guest_Jordan_*

Guest_Jordan_*
  • Guests
You can use the SUM() function to make a total.

SELECT SUM(<columnName>) ...

I think this is what you are asking.

#9
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
I already tried that, it didn't work. Hmm...
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#10
Brandon W

Brandon W

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 4,828 posts
Does it show an error or just doesn't show anything at all?
jQuery Selectors Tutorial - jQuery Striped Table tutorial - jQuery Events - jQuery Validation

Sorry if I don't post as often as I did, I'll try to get here as much as possible! I'm working my bum off to get this scholarship and other stuff!


#11
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
The MySQL query becomes invalid.

Anyway, I couldn't be bothered to spend time on it, so I just ditched the SQL countup and did it in a PHP loop as you suggested. It can be viewed at Welcome to Stav Cinemas and no, that money is not real.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#12
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
The MySQL query becomes invalid.

Anyway, I couldn't be bothered to spend time on it, so I just ditched the SQL countup and did it in a PHP loop as you suggested. It can be viewed at Welcome to Stav Cinemas and no, that money is not real.
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums