943,867 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 712
  • MySQL RSS
Jan 28th, 2009
0

What query do i need???

Expand Post »
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.

MySQL Syntax (Toggle Plain Text)
  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]
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NoGood is offline Offline
9 posts
since Nov 2008
Feb 3rd, 2009
0

Re: What query do i need???

Use Left outer Join

sql Syntax (Toggle Plain Text)
  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.
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008
Feb 3rd, 2009
0

Re: What query do i need???

Excellent thank you
Reputation Points: 10
Solved Threads: 0
Newbie Poster
NoGood is offline Offline
9 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: Need Suggestion
Next Thread in MySQL Forum Timeline: Move mysql colum to another table





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC