What query do i need???

Reply

Join Date: Nov 2008
Posts: 9
Reputation: NoGood is an unknown quantity at this point 
Solved Threads: 0
NoGood NoGood is offline Offline
Newbie Poster

What query do i need???

 
0
  #1
Jan 28th, 2009
Hi all,

I'm creating an appointments scheduling system. I have a bookings table and a time table among others in a MySQL database. Each entry in the bookings table has a slotId value. In the time table each slotId has a startTime and an endTime.

This is what i want to do.

I want a sql query to run so that when you enter a date and stylist into a form it runs a query and brings back all timeSlots available on that date with that stylist.

I have this query which is bringing back all the appointments on the date specified.

  1.  
  2. <?php
  3. if ($_POST["newSearch"]=="yes") {
  4.  
  5. $thisDate=$_POST["date"];
  6. $dd=substr($thisDate,0,2);
  7. $mm=substr($thisDate,3,2);
  8. $yyyy=substr($thisDate,6,4);
  9. $date="$yyyy-$mm-$dd";
  10. $stylist=$_POST["stylist"];
  11.  
  12. include("dbVariables.php");
  13.  
  14. // connect to database
  15. $db = mysql_connect($dbHost, $dbUsername, $dbPassword);
  16. mysql_select_db($databasename,$db);
  17.  
  18. $dbQuery = "SELECT * FROM bookings,time WHERE bookings.date='$date' AND bookings.stylist='$stylist' AND bookings.slotId=time.slotId ORDER BY time.startTime";
  19. $result = mysql_query($dbQuery, $db);
  20. $num=mysql_numrows($result);
  21. mysql_query($dbQuery) OR die('Error, insert query failed');
  22.  
  23. echo "<table width='100%' border='solid' bordercolor='darkcyan'> <tr><td>Time<td><td>Stylist</td></tr>\n";
  24. echo "</table>\n";
  25.  
  26. while ($dbRow=mysql_fetch_array($result)) {
  27.  
  28. echo"<form style=\"display:inline\" action=\"book.php\" method=\"post\">\n " .
  29.  
  30. "<table width='100%' border='solid' bordercolor='darkcyan'>\n " .
  31. "<tr><td>" . $dbRow['startTime'] . " - " . $dbRow['endTime'] . </td>\n " .
  32. "<td>" . $dbRow['stylist'] . </td>\n " .
  33. "</form>\n " ;
  34. }
  35. echo "</table><p>&nbsp;</p>\n";
  36. }
  37. ?>

But i want it to do the opposite and bring back all the slotId's on the specified date that have not been allocated an appointment.

Any suggestions??

Thanks
Last edited by peter_budo; Jan 30th, 2009 at 2:36 pm. Reason: Correcting closing tag from [code] to [/code]
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: What query do i need???

 
0
  #2
Feb 3rd, 2009
Use Left outer Join

  1. SELECT bookings.*,times.slotId FROM bookings
  2. LEFT OUTER JOIN TIME
  3. on bookings.slotId=TIME.slotId
  4. WHERE bookings.DATE='$date' AND bookings.stylist='$stylist'
  5. ORDER BY TIME.startTime"
  6. having time.slotId is null
  7.  
Last edited by peter_budo; Feb 3rd, 2009 at 2:03 pm. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 9
Reputation: NoGood is an unknown quantity at this point 
Solved Threads: 0
NoGood NoGood is offline Offline
Newbie Poster

Re: What query do i need???

 
0
  #3
Feb 3rd, 2009
Excellent thank you
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for MySQL
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC