• Building a Show Schedule Manager
    33 replies, posted
For my latest project I am writing a Program Schedule Manager for my internet radio station. I have it so far that it will show ALL records regard less of time or day. Now what I am working at is splitting the record sets up in to days and sorting the lists by time in descending ascending order (from top to bottom). Here is my attempt at doing this. I know I am doing something wrong but I can't figure out what. When using this function I get the following Warning. [B]Warning: Invalid argument supplied for foreach() in /home/powercas/public_html/PowerCastRadio/schedule-app/schedule.php on line 15[/B] Which equates to it getting no data (eg. an empty array) but I can't figure out why. [PHP] function getFridayShows () { if($Friday == 1){ $query = "SELECT '$Friday' FROM PCR_Show_Schedule"; $result = mysql_query($query); if($result == false) { echo "Query Failed for reason '" . mysql_error() . "'"; return false; } while ($row_ID = mysql_fetch_array($result)) $FridayShows[] = $row_ID; sort($FridayShows, SORT_NUMERIC); return $FridayShows; } [/PHP] phpMyAdmin Table: [url]http://grab.by/lYUc[/url]
I'm not sure if $Friday comes from user input, but if it does, $Friday will equal 1 whether $Friday is actually 1 or if $Friday is an unescaped SQL statement. You should either use === or escape it first.
Or, simply, not add variables where they aren't needed. If it's a function that will always get the shows on [B]Friday[/B], then that day is never going to change, so you can just add it according to the sql table. Something like "SELECT 'friday' FROM PCR_Show_Schedule".
[QUOTE=Amiga OS;40421619]Your query looks a little funky, I think it should be something like this. "SELECT from PCR_Show_Schedule WHERE Friday = 1" I also highly recommend looking up PDO, prepared SQL statements are far more secure. Also, where is the function getting $Friday from? it isn't being passed to it as an argument.[/QUOTE] Ok. Trying your modified query gives me the following error: [B]Query Failed for reason 'You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from PCR_Show_Schedule WHERE Friday === 1' at line 1'[/B] I am also a little perplexed by supersnail11's statement.
he's talking about the PHP line where you check to see if $Friday == 1, not the check in SQL. In PHP === means exactly equal, in SQL === means nothing.
[QUOTE=KmartSqrl;40422521]he's talking about the PHP line where you check to see if $Friday == 1, not the check in SQL. In PHP === means exactly equal, in SQL === means nothing.[/QUOTE] Right. Thanks for clearing that up. although when I try: [code]SELECT 'Friday' FROM PCR_Show_Schedule[/code] all I get is: [Quote]Array ( [0] => Array ( [0] => Friday [Friday] => Friday ) [1] => Array ( [0] => Friday [Friday] => Friday ) )[/Quote] If you would like I could post a link to a ZIP-archive of the code so you could get a closer look. Thanks for all the help!
Thanks! Now then if my thinking is correct... this code in the class: [PHP] function getDayShows ($Day) { $query = "SELECT * FROM PCR_Show_Schedule WHERE $Day = 1"; $result = mysql_query($query); if($result == false) { echo "Query Failed for reason '" . mysql_error() . "'"; return false; } while ($row_ID = mysql_fetch_array($result)) $FridayShows[] = $row_ID; sort($FridayShows, SORT_NUMERIC); return $Shows; } /** End Day Based Display **/ [/PHP] and if I pass the day in like this in the page: [PHP]$Shows = $Schedule->getDayShows($Day = "Friday");[/PHP] I should be able to get the output for each using one function instead of making seven separate functions, one for each day. Right? I fear that I way off the mark here though.
[PHP] function getShowsOnDay ($Day) { $query = "SELECT * FROM PCR_Show_Schedule WHERE $Day = 1"; $result = mysql_query($query); if($result == false) { echo "Query Failed for reason '" . mysql_error() . "'"; return false; } while ($row_ID = mysql_fetch_array($result)) $Shows[] = $row_ID; sort($Shows, SORT_NUMERIC); return $Shows; } [/PHP] So here is our function that outputs the shows based on day but now it needs to be sorted by time. This is why I chose to use 24-hour format to alliterative some of the pain it would cause to deal with 12-hour. Regardless of all that I don't think I am using the right function or I am probably using it wrong. Am I right in using the sort() function that PHP provides?
Now the part comes where I need to figure out how to handle it when there are no records returned. Thanks!
At the risk of confusing you, the best, but much more complex way to do this would be a relational database with a 'shows' table and an 'airings' table. 'shows' would have id (auto-incrementing, primary key), title, description. 'airings' would have id (auto-incrementing, primary key), showId, time (Datetime), season, episode, episodeDesc. You'd then be able to store much more information but would need much more complex queries to get the information you want. [CODE] "SELECT shows.title, shows.description, airings.time, airings.season, airings.episode, airings.episodeDesc FROM shows LEFT JOIN airings ON shows.id = airings.showId WHERE DAYNAME(airings.time) = '".$day."' ORDER BY airings.time" [/CODE] This would fetch any airings on the day specified ordered by airing. This is not what I really suggest you do, your solution is adequate, this is mainly to let you know that there are better ways to do things.
[QUOTE=CBastard;40425580]At the risk of confusing you, the best, but much more complex way to do this would be a relational database with a 'shows' table and an 'airings' table. 'shows' would have id (auto-incrementing, primary key), title, description. 'airings' would have id (auto-incrementing, primary key), showId, time (Datetime), season, episode, episodeDesc. You'd then be able to store much more information but would need much more complex queries to get the information you want. [CODE] "SELECT shows.title, shows.description, airings.time, airings.season, airings.episode, airings.episodeDesc FROM shows LEFT JOIN airings ON shows.id = airings.showId WHERE DAYNAME(airings.time) = '".$day."' ORDER BY airings.time" [/CODE] This would fetch any airings on the day specified ordered by airing.[/QUOTE] Thanks for the help but that just lost me completely. The goal of this was to be as simple and quick as possible. [editline]25th April 2013[/editline] Here it is! [url]http://www.powercastradio.net/schedule-app/[/url] This is the schedule page without dummy data. It contains an accurate schedule for the station. There is a static version of it that is live on the site however when this page is done it will be incorporate via a file_get_contents() call. So ignore that fact that it is technically invalid HTML for now. Now I just I just need to do the data management portion.
mysql is deprecated in PHP and should not be used. use mysqli instead.
Ok. So now I am on to working on the admin page. I can deal with the editing and deleting (in fact I have deleting working, it just commented out so people cant screw with it right now). The one thing that has me thinking is on this page how do I get it so it only shows on record of a given show despite the fact it appears on separate days. [url]http://www.powercastradio.net/schedule-app/[/url] This is current function I am using: [PHP] /** Begin Generalized Display **/ function getAllShows () { $query = "SELECT * FROM PCR_Show_Schedule"; $result = mysql_query($query); if($result == false) { echo "Query Failed for reason '" . mysql_error() . "'"; return false; } else if (mysql_num_rows($result) == 0) { return $_POST ['error'] = "NoRecords"; } while ($row_ID = mysql_fetch_array($result)) $Books[] = $row_ID; return $Books; } /** End Generalized Display **/ [/PHP]
[QUOTE=Wymoree;40431757]Ok. So now I am on to working on the admin page. I can deal with the editing and deleting (in fact I have deleting working, it just commented out so people cant screw with it right now). The one thing that has me thinking is on this page how do I get it so it only shows on record of a given show despite the fact it appears on separate days. [url]http://www.powercastradio.net/schedule-app/[/url] This is current function I am using: [PHP] /** Begin Generalized Display **/ function getAllShows () { $query = "SELECT * FROM PCR_Show_Schedule"; $result = mysql_query($query); if($result == false) { echo "Query Failed for reason '" . mysql_error() . "'"; return false; } else if (mysql_num_rows($result) == 0) { return $_POST ['error'] = "NoRecords"; } while ($row_ID = mysql_fetch_array($result)) $Books[] = $row_ID; return $Books; } /** End Generalized Display **/ [/PHP][/QUOTE] [QUOTE=P1raten;40430353]mysql is deprecated in PHP and should not be used. use mysqli instead.[/QUOTE]
[QUOTE=P1raten;40433878][/QUOTE] I saw your post. Just because I didn't respond to it directly doesn't mean that didn't read it. Regardless of that I thought that mysql*() was deprecated. Does that not include mysqli()?
[QUOTE=Wymoree;40435206]I saw your post. Just because I didn't respond to it directly doesn't mean that didn't read it. Regardless of that I thought that mysql*() was deprecated. Does that not include mysqli()?[/QUOTE] No, it doesn't. mysqli is the improved version.
[QUOTE=Wymoree;40435206]I saw your post. Just because I didn't respond to it directly doesn't mean that didn't read it. Regardless of that I thought that mysql*() was deprecated. Does that not include mysqli()?[/QUOTE] Assuming that you know something without any real facts behind it is what will prevent you from becoming a better programmer. All you have to do is ask or read up on the subject.
I think you shouldn't use mysqli either. Try PDO for best results. [url]http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/[/url]
[QUOTE=P1raten;40440834]Assuming that you know something without any real facts behind it is what will prevent you from becoming a better programmer. All you have to do is ask or read up on the subject.[/QUOTE] Or maybe I have a learning disability and have a tendency to misunderstand somethings. [editline]27th April 2013[/editline] I think I am going to go with MySQLi so I don't have to completely rewrite my __construct function. Regardless of the MySQLi/PDO argument my two latest annoyances are: [QUOTE=P1raten;40433878][/QUOTE] Disregarding the quote about the mysql stuff. and the fact I can't get data loaded in to a form so I can edit it. If anyone wants to look at all of the code: [url]https://github.com/phillf/ProgramScheduleManager[/url]
First off, I want to apologize for my little outburst yesterday. I was a little upset with certain people posting and reposting and reqouting certain things that I had read (and not actually responded to). There was no need to take my anger out on all of you. If anything I should have PMed whoever it was and dealt with it that way. Secondly, I know some of you probably think of me a dumb for waiting to do the rewrite of the database connect() function but I'd rather wait and sort out the other little stuff first so that this is usable in a live environment because I really need to replace the static page that is our current schedule at PowerCast and make it easier for those who don't know HTML to update themselves. The last two things I have the deal with (Then I will rewrite the function to use MySQLi.): - Show Editing - I can't seem to figure out why data won't load in to the form. - Display on the admin page - I also can't seem to figure out how to get it to display a show once regardless of how many days it may appear on. GitHub Repo: [url]https://github.com/phillf/ProgramScheduleManager[/url]
[QUOTE=Wymoree;40459349]First off, I want to apologize for my little outburst yesterday. I was a little upset with certain people posting and reposting and reqouting certain things that I had read (and not actually responded to). There was no need to take my anger out on all of you. If anything I should have PMed whoever it was and dealt with it that way. Secondly, I know some of you probably think of me a dumb for waiting to do the rewrite of the database connect() function but I'd rather wait and sort out the other little stuff first so that this is usable in a live environment because I really need to replace the static page that is our current schedule at PowerCast and make it easier for those who don't know HTML to update themselves. The last two things I have the deal with (Then I will rewrite the function to use MySQLi.): - Show Editing - I can't seem to figure out why data won't load in to the form. - Display on the admin page - I also can't seem to figure out how to get it to display a show once regardless of how many days it may appear on. GitHub Repo: [url]https://github.com/phillf/ProgramScheduleManager[/url][/QUOTE] For what you are doing I suggest you have a look at composer. You are including files here and there and it's much easier using composer.
[CODE]$AirTime = $_GET['AirTime']; $EndTime = $_GET['EndTime']; $ShowName = $_GET['ShowName']; $ShowDesc = $_GET['ShowDesc']; $Sunday = $_GET['Sunday'];[/CODE] You have to get those information from your database by using the ID you are already passing to the script via the URL parameter. [CODE]<a href="./editShow.php?ID=<?php echo $Show["ID"] ?>" target="_blank">Edit Show</a>[/CODE] The variables above are all empty because you are not passing them to the script - don't do this btw. Instead create a method called getShow($id) in your ScheduleClass where you ONLY select the show with the ID you are passing to this function. (SELECT * FROM x WHERE ID = y"). Then you can populate the edit form with the data. I didn't take a closer look to your code to get into detail, but you may figure it out yourself.
Ok. I have got it loading data. The latest changes are in the repo. Where I am lost is dealing with the times and day. Can anyone suggest an efficient way of handling either? Air/End Time Droipdown [CODE] <td> <select name="AirTime"> <?php for($i = 0; $i < 24; $i++): ?> <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option> <?php endfor ?> </select> </td> [/CODE] An example of the day code: [CODE] <tr> <td>Does this show air on Sunday?</td> <td>Yes<input type="radio" name="Sunday" value="1" /></td> <td>No<input checked="yes" type="radio" name="Sunday" value="0" /></td> </tr> [/CODE] I have an Ideas for this but it is extremely convoluted and inefficient.
[QUOTE=Wymoree;40469659]Ok. I have got it loading data. The latest changes are in the repo. Where I am lost is dealing with the times and day. Can anyone suggest an efficient way of handling either? Air/End Time Droipdown [CODE] <td> <select name="AirTime"> <?php for($i = 0; $i < 24; $i++): ?> <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option> <?php endfor ?> </select> </td> [/CODE][/QUOTE] That's incredibly obtuse. Put some comments on it saying what it does or something.
Sorry. My brain is not working anymore. [PHP] //This dropdown displays time in 12-hour format but actually saves the data in 24-hour format. This is the time a given show starts. <td> <select name="AirTime"> <?php for($i = 0; $i < 24; $i++): ?> <option value="<?= $i; ?>"><?= $i % 12 ? $i % 12 : 12 ?>:00 <?= $i >= 12 ? 'pm' : 'am' ?></option> <?php endfor ?> </select> </td> [/PHP]
I am a little confused as to why PHP is giving me these warnings. Can anyone explain? [QUOTE=PHP]Warning: Missing argument 12 for ScheduleClass::saveShow(), called in /home/powercas/public_html/PowerCastRadio/schedule-app/includes/saveShow.php on line 15 and defined in /home/powercas/public_html/PowerCastRadio/schedule-app/includes/ScheduleManager.class.php on line 108 Warning: Cannot modify header information - headers already sent by (output started at /home/powercas/public_html/PowerCastRadio/schedule-app/includes/ScheduleManager.class.php:108) in /home/powercas/public_html/PowerCastRadio/schedule-app/includes/ScheduleManager.class.php on line 116[/QUOTE] Latest Commit: [url]https://github.com/phillf/ProgramScheduleManager/commit/3d14e7b16e38e869c77756ecff3c1e28d2fcb365[/url]
When you are calling saveShow on line 15 of saveShow.php you are missing one of the arguments ($ID) so it is not seeing the 12th argument. Exactly what the error says :P The second error is caused by trying to change headers after you have already sent any of the request body to the user. You have to make sure that any code that modifies headers happens before you print ANY of the html on your page. It could be being caused by the other error printing though, so fix the first one first.
[QUOTE=KmartSqrl;40480627]When you are calling saveShow on line 15 of saveShow.php you are missing one of the arguments ($ID) so it is not seeing the 12th argument. Exactly what the error says :P The second error is caused by trying to change headers after you have already sent any of the request body to the user. You have to make sure that any code that modifies headers happens before you print ANY of the html on your page. It could be being caused by the other error printing though, so fix the first one first.[/QUOTE] That is fixed now however saving doesn't work and I am still trying to work out an efficient way of dealing with the days. I am still not sure how to deal with the AirTime and EndTime dropdowns either. Is this a proper query?: [CODE] UPDATE PCR_Show_Schedule SET `AirTime` = '".$AirTime."', `EndTime` = '".$EndTime."', `ShowName` = '".$ShowName."' , `ShowDesc` = '".$ShowDesc."' , `Sunday` = '".$Sunday."' , `Monday` = '".$Monday."' , `Tuesday` = '".$Tuesday."' , `Wednesday` = '".$Wednesday."' , `Thursday` = '".$Thursday."' , `Friday` = '".$Friday."' , `Saturday` = '".$Saturday."' WHERE `ID` = '".(int)$ID."'" [/CODE]
Can anyone help? This dropdowns still baffle me to this day and I can't figure it out.
Sorry, you need to Log In to post a reply to this thread.