Hello all, I need some help with echo function in php

Hello,
Not sure where i should begin with this(building a tvguide, xmltv epg data is in the mysql server) , my echo calls mysql and mysql returns start and stop date and time plus ofc the other data i ask for but thats not important here i want to just display parts of the output based on the date and time returned from the mysql. Like current date and time + 3h(so i can see whats on now and eg. 3hours ahead). Like echo is now it displays all times and all the programmes for 24h. Ill post the code :

[php]

<?php mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $sql="select channel, start, stop, start_date, title, desc from programmes where channel = 'disneychannel.no' "; $rs=mysql_query($sql) or die($sql.">>".mysql_error()); $num=mysql_num_rows($rs); if($num>0){ echo ""; echo ""; echo ""; echo ""; echo ""; echo ""; # echo ""; echo ""; while($row=mysql_fetch_array($rs)){ extract($row); echo ""; echo ""; echo ""; echo ""; echo ""; # echo ""; echo ""; } echo "
channelstartstoptitledesc
{$channel}{$start}{$stop}{$title}{$desc}
";//end table }else{ //if no records found echo "No records found."; } ?>

[/php]

this displays:

disneychannel.no 2011/12/10 06:20:00 2011/12/10 06:45:00 Fairly Odd Parents
disneychannel.no 2011/12/10 06:45:00 2011/12/10 07:10:00 Sabrina The Animated Series
disneychannel.no 2011/12/10 07:10:00 2011/12/10 07:35:00 Lykke til, Charlie!
disneychannel.no 2011/12/10 07:35:00 2011/12/10 08:00:00 Art Attack
disneychannel.no 2011/12/10 08:00:00 2011/12/10 09:10:00 Q-gjengen
disneychannel.no 2011/12/10 09:10:00 2011/12/10 09:20:00 En god latter!
disneychannel.no 2011/12/10 09:20:00 2011/12/10 09:30:00 En god latter!

etc… so you can see that its too much data to display 24h of programming for lets say 10 channels, so idealy I need to get the local time on the server, drop the data before that time and display whats on now and eg 3h ahead.

Input greatly apreciated.

Thanks

Emph

was thinking that this can be done kinda like this way too:

[php]
$sql=“select channel, start, stop, start_date, title, desc from programmes
where start = '”.date(“y/m/d H:i:S”, time() + 3)."’");
[/php]

but this does no output what so ever…

if I choose one of the values from the db like
[php]
$sql=“select channel, start, stop, start_date, title, desc from programmes
where start = ‘2011-12-10 04:00:00’”);
[/php]

it shows the channels and programming for the spesified time.

can anybody see anything wrong here? any other way of doing this? been spending the day scratching my head about this to make the wife happy :smiley:

Not an expert, but there is a mysql command “limit” if you limit the mysql to say 10 results and use ORDER BY datestamp that might help. I might be completely wrong, I’m just finding my way with PHP/MySql so…hope this helps

You can use the php DATE() function to get the current time from the server, store this as a $ variable, then possibly say something like

“SELECT channel, start, stop, start_date, title, desc FROM programmes WHERE time=$time AND channel = ‘disneychannel.no’ LIMIT 10”);

this is not exact code, I’m just trying to help suggest something…I know what it’s like to be a bit stuck

Ty for input jellygraphics,

I got something working, its not optimal but here is what i did
[php]
$mydatetime = date(‘Y-m-d H%’);
$mydatetime2 = date(‘Y-m-d H%’, strtotime("+3 hours"));

$sql=“select channel, start, stop, start_date, title, desc from programmes where start between ‘$mydatetime’ and ‘$mydatetime2’ and channel = ‘disneychannel.no’”;
[/php]

and this gives me a ok result but i will try to slap on eg. -25min on mydatetime to not miss to much of current programming. any input on how to make this better will be greatly apreciated.

thanks

Another question, going back to echo

[php]

echo “

{$start}”;
[/php]

gives me the output of datetime : 2011-12-11 19:00:00

is there any way of getting rid of 2011-12-11 and just keep the time there? was trying with a if statement but if i choose y m d = current date then ofcourse it will drop the whole echo so need some something that reads it but only output the time…

Hi there,

You can use PHP’s date function to format dates and times to how ever you like it to be. Try the following (too tired to see if both lines can be combined into one using the double-quotes:

[php]$start = date(‘H:i:s’, $start);
echo “

{$start}”;[/php]

Like I said, I don’t know if you can put the date function inside of the double-quotes or not I’m just too tired to try. Hope this helps.

Sponsor our Newsletter | Privacy Policy | Terms of Service