Highland3r Posted December 23, 2008 Share Posted December 23, 2008 not sure if I'm trying to be too adventures but what i would like to do is have an area of my site which displays a different id in the same mySQL table at different times of the day, IE say a breakfast show had a DJ on at 9o'clock then at 10o'clock the DJ changed could i create a code that would automatically update the now playing DJ for me ? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/ Share on other sites More sharing options...
ngreenwood6 Posted December 23, 2008 Share Posted December 23, 2008 yes you can. I would look into the date() function. do you know the times that the dj are going to be playing or how would you like it to update? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-722802 Share on other sites More sharing options...
Highland3r Posted December 24, 2008 Author Share Posted December 24, 2008 this is a part of mySQL and php im not too sure on the time() date() functions i know the times of the day the djs will be playing but the djs will change depending the day of the week but the djs will be the same time every week could you offer a tutorial script for me to see or something ? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-723087 Share on other sites More sharing options...
ngreenwood6 Posted December 24, 2008 Share Posted December 24, 2008 If you can elaborate more on your set up or show me some code I can help you with the date function in the meantime check this out: http://www.tizag.com/phpT/phpdate.php Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-723150 Share on other sites More sharing options...
Highland3r Posted December 27, 2008 Author Share Posted December 27, 2008 thanks for the suggested site i have looked their has been great help i think im getting the hang of php and mySQL thanks to you ngreenwood6 Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-724660 Share on other sites More sharing options...
Highland3r Posted December 28, 2008 Author Share Posted December 28, 2008 i thought i had solved the problem but appears not it works in one sense when you add the times etc it displays them in order soonest time first so arranges them like 10:00, 10:15, 10:30, ETC... but when 10:15 come it leaves the time 10:00 still showing here's the code i have so far  <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve articles $result = $connector->query('SELECT ID,name,photo,time,date FROM cmsschedule order by time ASC LIMIT 5'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['name']; echo $row['photo']; echo '<br>on at '; echo $row['time']; echo '<hr /></a> </p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-724851 Share on other sites More sharing options...
ngreenwood6 Posted December 28, 2008 Share Posted December 28, 2008 I think that you are missing a where clause: Â SELECT * FROM table WHERE time < '$time' Â that will pick the time that is less that a variable time. Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-724917 Share on other sites More sharing options...
Highland3r Posted December 28, 2008 Author Share Posted December 28, 2008 i have entered the code suggested but returns an error message of "Parse error: syntax error, unexpected T_VARIABLE in /home/sites/mydomain.co.uk/public_html/index.php on line 136" Â <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Execute the query to retrieve articles $time = $_GET["time"]; $result = $connector->query('SELECT * FROM cmsschedule WHERE time < '$time'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['name']; echo $row['photo']; echo '<br>on at '; echo $row['time']; echo '<hr /></a> </p>'; } ?> Â Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-724931 Share on other sites More sharing options...
ngreenwood6 Posted December 29, 2008 Share Posted December 29, 2008 sorry I think you misunderstood, that was just an example. what are you storing in the time field? is it a timestamp or what? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-725144 Share on other sites More sharing options...
Highland3r Posted December 29, 2008 Author Share Posted December 29, 2008 in the time field i m storing the dj start time ? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-725700 Share on other sites More sharing options...
Highland3r Posted January 2, 2009 Author Share Posted January 2, 2009 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-728035 Share on other sites More sharing options...
ngreenwood6 Posted January 2, 2009 Share Posted January 2, 2009 This is a little more confusing than you think it is. What do you store in the time field? Is it a timestamp (looks like this 130949832) or an actual time(10:00)? Also where does the time for the dj's get put into the database? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-728114 Share on other sites More sharing options...
Highland3r Posted January 3, 2009 Author Share Posted January 3, 2009 at the moment i have been manually entering the time into the time field on the database entered as the appropriate time IE time would equal 10:00 Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-728666 Share on other sites More sharing options...
Highland3r Posted January 5, 2009 Author Share Posted January 5, 2009 Anybody? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-730146 Share on other sites More sharing options...
ngreenwood6 Posted January 6, 2009 Share Posted January 6, 2009 You could try this: Â <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Set the time $start_time = time(); $time = date("H:i",$start_time) //this makes it 24 hour time (1 o'clock will be 13 and disply like 13:00) // Execute the query to retrieve articles $result = $connector->query('SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['name']; echo $row['photo']; echo '<br>on at '; echo $row['time']; echo '<hr /></a> </p>'; } ?> Â I cannot guarantee that this will work because you are not storing the time with the correct values. But in order for this to work you will need to use 24 hour time when you store it in the database. For example if you wanted something to show after noon it will start with 13 for 1 o'clock pm. When you put them in the database make sure you use 24 hour time. I did this so that this example might actually work with your set-up (not sure though). Please let me know the results. Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-730607 Share on other sites More sharing options...
Highland3r Posted January 6, 2009 Author Share Posted January 6, 2009 i have used the code provided i can slightly understand what it is doing but i am given this error  Parse error: syntax error, unexpected T_VARIABLE in /home/sites/mydomain.co.uk/public_html/index.php on line 140  the line in question is  $result = $connector->query('SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5');  any help appreciated Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-730786 Share on other sites More sharing options...
ngreenwood6 Posted January 7, 2009 Share Posted January 7, 2009 try this: Â $result = $connector->query("SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= 'time' order by time ASC LIMIT 5"); Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-731972 Share on other sites More sharing options...
Highland3r Posted January 9, 2009 Author Share Posted January 9, 2009 have tried the new code but still getting the same error ? any suggestions ? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-733671 Share on other sites More sharing options...
ngreenwood6 Posted January 10, 2009 Share Posted January 10, 2009 Sorry I forgot the $ in time: Â $result = $connector->query("SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5"); Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-734236 Share on other sites More sharing options...
Highland3r Posted January 10, 2009 Author Share Posted January 10, 2009 nah wasnt that tried that already canna seem to see why its not working it should be :S any ideas? the error i get is Parse error: syntax error, unexpected T_VARIABLE in /home/sites/mydomain.co.uk/public_html/index.php on line 140  this reffers to the bit of code above  $result = $connector->query("SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5"); Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-734332 Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 Can you post all of your code from this page? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-735221 Share on other sites More sharing options...
Highland3r Posted January 12, 2009 Author Share Posted January 12, 2009 <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Set the time $start_time = time(); $time = date("H:i",$start_time) //this makes it 24 hour time (1 o'clock will be 13 and disply like 13:00) // Execute the query to retrieve articles $result = $connector->query("SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5")); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['name']; echo $row['photo']; echo '<br>on at '; echo $row['time']; echo '<hr /></a> </p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-735356 Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 Forgot a ; on the line before it  try this <?php // Require the database class require_once('includes/DbConnector.php'); // Create an object (instance) of the DbConnector $connector = new DbConnector(); // Set the time $start_time = time(); $time = date("H:i",$start_time); //this makes it 24 hour time (1 o'clock will be 13 and disply like 13:00) // Execute the query to retrieve articles $result = $connector->query("SELECT ID,name,photo,time,date FROM cmsschedule WHERE time >= '$time' order by time ASC LIMIT 5")); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo $row['name']; echo $row['photo']; echo '<br>on at '; echo $row['time']; echo '<hr /></a> </p>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-735405 Share on other sites More sharing options...
Highland3r Posted January 12, 2009 Author Share Posted January 12, 2009 thanks m8 once again i ow you one thanks for all your help its appreciated Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-735411 Share on other sites More sharing options...
ngreenwood6 Posted January 12, 2009 Share Posted January 12, 2009 No problem. Most of the time when you get errors look on the line that it is referring to and up 2 lines and down 2 lines and you will find the problem more than likely. Did this work for you? Quote Link to comment https://forums.phpfreaks.com/topic/138232-solved-mysql-display-data-relevant-to-time-of-day/#findComment-735414 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.