156418 Posted December 7, 2006 Share Posted December 7, 2006 Hi, I think there's probably an easy way to do this, but its got me a little confused.I would like to Run a query, which selects two tables, Callbacks and TicketsSold.Then I'd like to display the contents of Callbacks, where the cartID = cartID in TicketsSold, and where MC_EventDate equals either:Saturday 9th DecemberSunday 10th DecemberSaturday 16th DecemberSunday 17th DecemberSaturday 23rd December.I will have 5 seperate pages, so I can hard code the date into the query, but am struggling on how to put the query togther to get the necessary results. Do I need to run seperate queries on the tables then merge them somehow?I have PHP version 4.4.2 and MySQL version 4.1.21-standard if that makes a differenceMany thanks for any pointers. Quote Link to comment Share on other sites More sharing options...
Vikas Jayna Posted December 7, 2006 Share Posted December 7, 2006 It can happen in a single query using a join:-[code]select Callbacks.* from Callbacks,TicketsSold where Callbacks.cartID = TicketsSold.cartID and MC_EventDate in ('2006-12-09','2006-12-10','2006-12-16','2006-12-17','2006-12-23')[/code] Quote Link to comment Share on other sites More sharing options...
obsidian Posted December 7, 2006 Share Posted December 7, 2006 [quote author=Vikas Jayna link=topic=117705.msg480457#msg480457 date=1165498113]It can happen in a single query using a join:-[code]select Callbacks.* from Callbacks,TicketsSold where Callbacks.cartID = TicketsSold.cartID and MC_EventDate in ('2006-12-09','2006-12-10','2006-12-16','2006-12-17','2006-12-23')[/code][/quote]Right on... and as a side note to the initial poster, when you're dealing with advanced queries, your MySQL version is much more important than your PHP version. PHP simply initiates the query. All the brunt of the processing is handled by MySQL directly. With that being said, you should always attempt to allow your database server to do as much of the processing as possible to keep your PHP resources free for other things. Quote Link to comment Share on other sites More sharing options...
156418 Posted December 7, 2006 Author Share Posted December 7, 2006 Thanks for the help, I've got it working as I want, just have one problem.I had to change the query slightly as the date is in the database as text rather than in Date Format. However the problem is that each record which is returned is displayed 3 times[code]<?phprequire('db_connect.php');?> <?php$query = "select Callbacks.* from Callbacks,TicketsSold where Callbacks.cartId = TicketsSold.OrderID and MC_EventDate in ('Saturday 9th December')";$results = mysql_query($query) or die(mysql_error());?></head><body><p>Attendance List: Saturday 9th December 2006</p><p> <?phpwhile ($row = mysql_fetch_array($results)) { extract($row); echo "Callback Number: $CallbackNo <br>"; echo "Customer Name: $customername <br>"; echo "Customer Address: $customeraddress <br>"; echo "Ticket Details: $M_disc <br>";}?>[/code]Any ideas as to what I've done wrong? Quote Link to comment Share on other sites More sharing options...
156418 Posted December 7, 2006 Author Share Posted December 7, 2006 Never mind, solved it by GROUP BY now.Many thanks for all the help, this was a system I've taken over the administration of, at least after this event i'll have the time to scrap this Database and start with a new one taking out all the multiple tables which have made it confusing! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.