Jump to content

[SOLVED] MySQL display data relevant to time of day?


Highland3r

Recommended Posts

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 ?

Link to comment
Share on other sites

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 ?

Link to comment
Share on other sites

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>';

}

?>

Link to comment
Share on other sites

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>';
}
?>

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

<?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>';
}

?>

Link to comment
Share on other sites

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>';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.