|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
I'm not much of a programmer, but can usually figure simple things out w/ the code in front of me. Here I need some code added, so any help would be appreciated! I have a TV Listings page on one of my sites. (I add/delete listings via phpMyAdmin). On another site, I would like to access that database but just display the results for today ("What's on Today") Here is the original code:
<?php
$db_name = "XXXXXXX_gftv";
$table_name = "GFTV";
$connection = @mysql_connect("localhost", "XXXXXXX", "XXXXXXX")
or die("Couldn't connect.");
$db = @mysql_select_db($db_name, $connection)
or die("Couldn't select database.");
$sql = "SELECT ID, DayOfWeek, Month, Day, Year, Movie, Channel, AirTime
FROM $table_name
ORDER BY Year, Month, Day, AirTime
";
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
while ($row = mysql_fetch_array($result)) {
$ID = $row['ID'];
$DayOfWeek = $row['DayOfWeek'];
$Month = $row['Month'];
$Day = $row['Day'];
$Year = $row['Year'];
$Movie = $row['Movie'];
$Channel = $row['Channel'];
$AirTime = $row['AirTime'];
$display_block .= "
<TR>
<TD bgcolor=#eeeeee><FONT size=2 face='Verdana, Arial, Helvetica, sans-serif'>$DayOfWeek $Month/$Day</FONT><BR></TD>
<TD bgcolor=#ffffff><FONT size=2 face='Verdana, Arial, Helvetica, sans-serif'><B>$Movie</B></FONT><BR></TD>
<TD bgcolor=#ffffff><FONT size=2 face='Verdana, Arial, Helvetica, sans-serif'>$Channel</FONT><BR></TD>
<TD bgcolor=#ffffff><FONT size=2 face='Verdana, Arial, Helvetica, sans-serif'>$AirTime</FONT><BR></TD>
</TR>
";
}
?>
Now, two questions...1) Is there an easy way to just display shows airing today? (on the second site) 2) How can I get it to sort by AirTime (tiny text) properly? Because it will display 10 PM before 1:30 PM, and 11:30 AM before 12 AM, etc. I really don't want to use 24-hour time if I can help it (or at least have it convert 24-hour time to 12-hour time?) Thanks for any guidance! JG PS - If it matters, here's the structure:
ID int(10) auto_increment
DayOfWeek tinytext
Month tinyint(2)
Day tinyint(2)
Year smallint(4)
Movie tinytext
Channel tinytext
AirTime tinytext
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Dec 2003
Posts: 1,796
Pooh-Bah
|
Pooh-Bah
Joined: Dec 2003
Posts: 1,796 |
Anyone? Buehler?
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Thanks for resurrecting this. I got the following reply on the ASO Forums, but I haven't tried coding it yet (since I'm not a programmer and don't know how to write queries ) Airing today is quite easy - you just need to use the PHP date function. Something like:
$today_day = date('j');
$today_month = date('n');
$today_year = date('Y');
should give you today's date as parts that you can then use in a query. As for sorting by "air time", you'd need to structure your data better. The problem is that you're storing two integers (one of which determines a third value) as a string of all three values concatenated. If you had "hour" (tinyint with values 0 - 23) and "min" (tinyint with values 0 - 59) you could do "order by hour, min" and then do:
if ($hour >=12)
{
$am_pm = 'pm';
$hour -= 12;
}
else
{
$am_pm = 'am';
}
To give you 12 hour clock times. Or just use the 24 hour clock. I don't really know how to do the first part so any help would be appreciated. As for the second part, I'm so used to typing in "1:30 PM" -or- "1PM" -or- "1PM/8PM" (sometimes something airs twice a day), etc, I'm not sure what to do. Perhaps some function could parse the first 1 or 2 digits (until it finds either a colon or space or letter A or letter P and sort from that? I wouldn't know how to do that, either. Hopefully someone there (or here) could help a little...
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jul 2006
Posts: 4,057
|
Joined: Jul 2006
Posts: 4,057 |
I do this to find a day.
$today = date("dm"); // <<<--- There just comment outs. // result == 2806 Day, Month
You can then do an Else if statement.
if ($today == ("2806")) { include ('birthday/birthday_header.inc.php'); } // Happy Birthday else if ($today == ("1111")) { include ('birthday/birthday_header2.inc.php'); }
// And if none of the conditions above are met do this. else { include ('default/default-header2.inc.php'); } // Normal Header.
So with the above, you have 2 True Conditions and 1 false. Which all can perform a different action. You will probably have to add the "Year" to the date? Google "php date". its probably a small "y" to equal "08" That will make the call appear only in that year.
BOOM !! Version v7.6.1.1 People who inspire me Isaac ME Gizmo
|
|
|
|
Joined: Jun 2006
Posts: 16,301 Likes: 116
|
Joined: Jun 2006
Posts: 16,301 Likes: 116 |
I prefer working off of the Unix Epoch, and store such data in the DB (never know when you'll want to quote it out to the browser and display it in a differant format)
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
I thought I had it by adding if ($Month == date("n") and $DayOfWeek == date("j")) but it's not displaying any results. Did I do something wrong? (Yes, I did do something wrong: I used $DayOfWeek instead of $Day -- never mind! )
$sql = "SELECT ID, DayOfWeek, Month, Day, Year, Movie, Channel, AirTime
FROM $table_name
ORDER BY AirTime
";
$result = @mysql_query($sql,$connection)
or die("Couldn't execute query.");
$today = date("nj"); echo $today; while ($row = mysql_fetch_array($result)) {
$ID = $row['ID'];
$DayOfWeek = $row['DayOfWeek'];
$Month = $row['Month'];
$Day = $row['Day'];
$Year = $row['Year'];
$Movie = $row['Movie'];
$Channel = $row['Channel'];
$AirTime = $row['AirTime'];
if ($Month == date("n") and $DayOfWeek == date("j")){
$display_block .= "
<TR>
<TD><FONT size='2' face='Verdana, Arial, Helvetica, sans-serif'>$AirTime</FONT><BR></TD>
<TD><FONT size='2' face='Verdana, Arial, Helvetica, sans-serif'><B>$Movie</B></FONT><BR></TD>
<TD><FONT size='2' face='Verdana, Arial, Helvetica, sans-serif'>$Channel</FONT><BR></TD>
</TR>
";
}
}
?>
<p align="center"><b><font size="3" face="Verdana, Arial, Helvetica, sans-serif">Today on TV</font></b></p>
<table cellspacing="0" cellpadding="4" align="center" border="1">
<tr>
<th><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Time (ET)</font></th>
<th><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Movie</font></th>
<th><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Chan</font></th>
</tr>
<!-- BEGIN : EMBED DATA FROM MYSQL DATABASE -->
<? echo "$display_block"; ?>
<!-- END : EMBED DATA FROM MYSQL DATABASE -->
</table>
Thanks
Last edited by jgeoff; 02/17/2008 4:39 PM.
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jul 2006
Posts: 4,057
|
Joined: Jul 2006
Posts: 4,057 |
Do you get a result from $today being echoed out? ( you do)
If so, you know where further down, i always have a nightmare with getting the sql query, not so much the query but the synthax.
Get the Database to out put something. I normally get it to output as much as possible then start adding if's and "ands"
Simplify that "IF" and get it to output. And it my be an idea while you are testing to make the day variable constant.
Its just a trial and error puzzle.
BOOM !! Version v7.6.1.1 People who inspire me Isaac ME Gizmo
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Simplify that "IF" and get it to output. And it my be an idea while you are testing to make the day variable constant. I'm an idiot!! I used $DayOfWeek (text) rather than $Day (int) Thanks for making me look at it more closely -- it works now!
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
After many new errors, I got it working in a custom island!! Woohoo!! Data taken from my main listings on one site displaying just "Today" in an island on my forums on another server -- I'm so proud of myself! lol Thanks, Mark
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Odd... while every time the page reloads, the php date changes no problem, but at 12:02 AM the listings themselves had yet to change until I cleared the BB cache. The island's cache refresh is set to 0 but that shouldn't matter with dynamic php code. Maybe I just don't know exactly how the cache works, but shouldn't my island change at 12AM?
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jul 2006
Posts: 4,057
|
Joined: Jul 2006
Posts: 4,057 |
Well your getting further than me because mine for some reason is being compromised in a content island. ?? Just check your Transition screen when submitting in the control panel. You need a couple of post and it will kick over
BOOM !! Version v7.6.1.1 People who inspire me Isaac ME Gizmo
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Never thought to wait for a new post to see if it'd kick over, I'll try that tonight - thanks Hey, if yours isn't working post it here now that I'm a Big Expert! (not really) lol
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jun 2006
Posts: 16,301 Likes: 116
|
Joined: Jun 2006
Posts: 16,301 Likes: 116 |
i helped someone do this before; but I forget who it was...
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jul 2006
Posts: 4,057
|
Joined: Jul 2006
Posts: 4,057 |
i helped someone do this before; but I forget who it was... Think Think lol
BOOM !! Version v7.6.1.1 People who inspire me Isaac ME Gizmo
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Oh, man... after over 13 hours past midnight my listings still didn't update until I cleared the forum cache. Why would it not do it automatically? I guess I'll have to set the island cache refresh after all? :/ It's just odd because the date/time updates with every page reload but the listings don't...
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Jul 2006
Posts: 4,057
|
Joined: Jul 2006
Posts: 4,057 |
If all fails you may have to run your external page as a cron job or something. Keep us posted
BOOM !! Version v7.6.1.1 People who inspire me Isaac ME Gizmo
|
|
|
|
Joined: Jun 2006
Posts: 16,301 Likes: 116
|
Joined: Jun 2006
Posts: 16,301 Likes: 116 |
well, my sugguestion would be to just use a phpinclude in your island; and have it call an external page, and put your code there... then the cached data would be the php include...
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
Not a bad idea - thanks
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
|
Joined: Aug 2006
Posts: 1,649 Likes: 1
Pooh-Bah
|
Pooh-Bah
Joined: Aug 2006
Posts: 1,649 Likes: 1 |
The 30 minute cache time I assigned works -- so at least I know it'll refresh w/in half an hour after midnight. Just a shame it has to do that 47 times more than it has to each day.
For tomorrow I'll try Gizzy's suggestion and see if that works any better...
GangsterBB.NET (Ver. 7.6.1.1) PHP Version 5.6.40 / MySQL 5.7.23-23 (was 5.6.41-84.1) / Apache 2.4.54 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP
|
|
|
0 members (),
375
guests, and
147
robots. |
Key:
Admin,
Global Mod,
Mod
|
|
|
|