Problem with SELECT statements.....
Posted by:
cdubks88
Date: May 26, 2005 04:18PM
I'm trying to work out an issue with a SELECT statement and can't seem to figure out the best way to do it.
I have a table with fields that I need to use for the SELECT, called event1, date1, time1, tix1 and I have six separate "sets" of those four fields (in other words, there's a corresponding event2, event3, event4, event5, event6....date2, date3, date4, date5, date6.....etc).
Right now, insertform.php page form method set to post to a page called insert2.php.
insert2.php contains the SELECT statement that needs to sum the number of tickets for a given event where any of three fields (event, date and time) are equal to the event, date and time submitted in the previous form.
I had done something like this (my apologies beforehand - I'm new to mysql and php):
$event1_query = "select SUM(tix1) AS event1_tix FROM table1 WHERE (((event1='$event1') AND (date1='$date1') AND (time1 = '$time1')) or ((event2='$event1') AND (date2='$date1') AND (time2 = '$time1')) or ((event3='$event1') AND (date3='$date1') AND (time3 = '$time1')) or ((event4='$event1') AND (date4='$date1') AND (time4 = '$time1')) or ((event5='$event1') AND (date5='$date1') AND (time5 = '$time1')) or ((event6='$event1') AND (date6='$date1') AND (time6 = '$time1')))";
$event1_result = mysql_query($event1_query) or die("Query: ".$event1_query."<br />\n\nError: ".mysql_error()."<br />\n");
$event1_tix = mysql_result($event1_result, 0, 0);
But I don't think that's right, because it will only giving me the sum of the number of tickets that are in tix1 column.
I couldn't seem to figure out how to do that right - do I need to include a SUM(tix2) + SUM(tix3) + SUM(tix4)....and so on - or something like that to qualify that right?
Thanks,
C.