943,685 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Unsolved
  • Views: 1416
  • MS SQL RSS
Jul 17th, 2008
0

Help with Database Query...

Expand Post »
Sorry, I posted this in the wrong area (I'm using MySQL)





Hello all:

I'm currently building a website for a radio station and I want to setup a programming lineup. The fields I'm using are:

ID
Title
Dayofweek (Show Day)
Timeslot (Show Time)
AMPM (AM or PM)
Description
Name (Host Name)
Bio (Host Bio)
Photo (Host Photo)

I set these all up as TEXT as I wasn't sure how to do it correctly.

I want to be able to make a schedule listing the shows by Day of Week and then by Time, and I also want to make a box showing the current program on the air.

Any ideas for a newbie????

Thanks all!

Alan
Last edited by ncognito66; Jul 17th, 2008 at 1:14 am.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ncognito66 is offline Offline
4 posts
since Jul 2008
Jul 22nd, 2008
0

Re: Help with Database Query...

I'd suggest using a view or a stored procedure. The syntax would be something like the following.

sql Syntax (Toggle Plain Text)
  1. SELECT DAYOFWEEK, MAX(Timeslot) as 'Timeslot', MAX(AM/PM) as 'AM/PM', MAX(Description) as 'Description', MAX(Name) as 'Name', MAX(BIO) as 'Bio', MAX(Photo) as 'Photo'
  2. FROM <TABLENAME>
  3. GROUP BY DAYOFWEEK
  4. ORDER BY DAYOFWEEK, MAX(Timeslot)
Last edited by peter_budo; Jul 23rd, 2008 at 8:25 pm. Reason: Keep It Organized - please use [code] tags
Reputation Points: 15
Solved Threads: 9
Junior Poster
cutepinkbunnies is offline Offline
143 posts
since Apr 2006
Jul 22nd, 2008
0

Re: Help with Database Query...

Thank you for your help, but I have other problems I guess.

Here's the form I'm using to input my data to the database:

MS SQL Syntax (Toggle Plain Text)
  1. <form action="<?=$PHP_SELF?>" method="post">
  2. <br>
  3. <b>Show Title</b>
  4. <br><input type="text" name="Title" size="50">
  5. <p><b>Day of Week</b>
  6. <br><input type="radio" name="Showday" value="Monday" checked> Monday&nbsp;
  7. <input type="radio" name="Showday" value="Tuesday"> Tuesday&nbsp;
  8. <input type="radio" name="Showday" value="Wednesday"> Wednesday&nbsp;
  9. <input type="radio" name="Showday" value="Thursday"> Thursday&nbsp;
  10. <input type="radio" name="Showday" value="Friday"> Friday&nbsp;
  11. <input type="radio" name="Showday" value="Saturday"> Saturday&nbsp;
  12. <input type="radio" name="Showday" value="Sunday"> Sunday
  13. <p><b>Show Date (2008-07-05)</b>
  14. <br><input type="text" name="Showdate" value="0000-00-00" size="50">
  15. <p><b>Show Time</b>
  16. <br><SELECT NAME="Timeslot">
  17. <option>01:00
  18. <option>01:15
  19. <option>01:30
  20. <option>01:45
  21. <option>02:00
  22. <option>02:15
  23. <option>02:30
  24. <option>02:45
  25. <option>03:00
  26. <option>03:15
  27. <option>03:30
  28. <option>03:45
  29. <option>04:00
  30. <option>04:15
  31. <option>04:30
  32. <option>04:45
  33. <option>05:00
  34. <option>05:15
  35. <option>05:30
  36. <option>05:45
  37. <option>06:00
  38. <option>06:15
  39. <option>06:30
  40. <option>06:45
  41. <option>07:00
  42. <option>07:15
  43. <option>07:30
  44. <option>07:45
  45. <option>08:00
  46. <option>08:15
  47. <option>08:30
  48. <option>08:45
  49. <option>09:00
  50. <option>09:15
  51. <option>09:30
  52. <option>09:45
  53. <option>10:00
  54. <option>10:15
  55. <option>10:30
  56. <option>10:45
  57. <option>11:00
  58. <option>11:15
  59. <option>11:30
  60. <option>11:45
  61. <option>12:00
  62. <option>12:15
  63. <option>12:30
  64. <option>12:45
  65. </SELECT>
  66. <p><b>AM/PM</b>
  67. <br><SELECT NAME="AMPM">
  68. <option>AM
  69. <option>PM
  70. </SELECT>
  71. <p><b>Show Duration</b>
  72. <br><input type="text" name="Duration" value="0:00" size="50">
  73. <p><b>Show Topic (Brief few word description)</b>
  74. <br><input type="text" name="Topic" size="50">
  75. <p><b>Show Description (Full length description)</b>
  76. <br><textarea wrap="virtual" cols="50" rows="12" name="Description"></textarea>
  77. <p><b>Host Name</b>
  78. <br><input type="text" name="Name" size="50">
  79. <p><b>Host Bio</b>
  80. <br><textarea wrap="virtual" cols="50" rows="12" name="Bio"></textarea>
  81. <p><b>Host Photo Filename</b>
  82. <br><input type="text" name="Photo" size="50">
  83. <br>
  84. <br>
  85. <br><input type="submit" name="submitshow" value="Submit Show"></form>

I insert the data with the following:

MS SQL Syntax (Toggle Plain Text)
  1. $sql = "INSERT INTO shows SET
  2. Title='$Title',
  3. Timeslot='$Timeslot',
  4. AMPM='$AMPM',
  5. Showday='$Showday',
  6. Showinfo='$Showinfo',
  7. Showdate='$Showdate',
  8. Duration='$Duration',
  9. Topic='$Topic',
  10. Description='$Description',
  11. Name='$Name',
  12. Bio='$Bio',
  13. Photo='$Photo'";

Notice I have separate fields for Showday (Day of Week), Showdate (Actual Date), Showtime (Time of show),and AM/PM. I guess my first problem is:

How do I merge those fields into a Date/Time form that MYSQL will recognize?

I originally had all the columns as TEXT which worked except 12:00 Noon came after 11:00PM, so I changed the Showdate column to DATE and Timeslot to TIME, but I still have the AM/PM problem.

Once I get the info inputted into MYSQL in the proper format, then I need to pull up schedules by week, day, and "Currently on the Air". But I need to know what I'm doing wrong with my data input first.

Thank you so much!!

Alan
<EMAIL SNIPPED>
Last edited by peter_budo; Jul 23rd, 2008 at 8:27 pm. Reason: Keep It On Site - Do not post asking for an answer to be sent to you via email or PM.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
ncognito66 is offline Offline
4 posts
since Jul 2008
Jul 23rd, 2008
0

Re: Help with Database Query...

It looks like your SQL syntax is incorrect. Read up on INSERT syntax here.

Please keep us updated on your progress/trial & error.
Reputation Points: 15
Solved Threads: 9
Junior Poster
cutepinkbunnies is offline Offline
143 posts
since Apr 2006
Jul 25th, 2008
0

Re: Help with Database Query...

Hello,

you may have a look at DATE_FORMAT(date, format), especially specifier %p to convert date and time values.

krs,
tesu
Reputation Points: 158
Solved Threads: 98
Master Poster
tesuji is offline Offline
720 posts
since Apr 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 MS SQL Forum Timeline: Stored Procedure to reliably update two tables.
Next Thread in MS SQL Forum Timeline: Data Type mismatch!! :( Breaking my head on this for days!!!





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


Follow us on Twitter


© 2011 DaniWeb® LLC