 |
 |
 |
 |
Registered: 12/29/03
Posts: 2020
|
|
|
 |
 |
 |
 |
|
 |
 |
 |
 |
#205976 - 02/04/08 04:22 PM
PHP Coding Help?
|
Pooh-Bah
|
Registered: 08/08/06
Posts: 1931
Loc: NJ
|
|
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.5.6) 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP Browsers: Chrome, Firefox, & Safari (Win7 and iPhone); No IE, ever!
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
|
Express Hosting
"We are the official hosting company of UBB.threads. Ask us about our free migration services to migrate your UBB.threads installation."
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
#206277 - 02/11/08 02:31 PM
Re: PHP Coding Help?
[Re: AllenAyres]
|
Pooh-Bah
|
Registered: 08/08/06
Posts: 1931
Loc: NJ
|
|
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.5.6) 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP Browsers: Chrome, Firefox, & Safari (Win7 and iPhone); No IE, ever!
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
#206602 - 02/17/08 01:58 PM
Re: PHP Coding Help?
[Re: Mark S]
|
Pooh-Bah
|
Registered: 08/08/06
Posts: 1931
Loc: NJ
|
|
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 
Edited by jgeoff (02/17/08 02:39 PM)
_________________________
GangsterBB.NET (Ver. 7.5.6) 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP Browsers: Chrome, Firefox, & Safari (Win7 and iPhone); No IE, ever!
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
#206605 - 02/17/08 02:35 PM
Re: PHP Coding Help?
[Re: Mark S]
|
Pooh-Bah
|
Registered: 08/08/06
Posts: 1931
Loc: NJ
|
|
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.5.6) 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP Browsers: Chrome, Firefox, & Safari (Win7 and iPhone); No IE, ever!
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
 |
 |
 |
 |
#206612 - 02/17/08 04:39 PM
Re: PHP Coding Help?
[Re: jgeoff]
|
Pooh-Bah
|
Registered: 08/08/06
Posts: 1931
Loc: NJ
|
|
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.5.6) 2007 Content Rulez Contest - Hon Mention UBB.classic 6.7.2 - RIP Browsers: Chrome, Firefox, & Safari (Win7 and iPhone); No IE, ever!
|
|
Top
|
|
|
|
|
 |
 |
 |
 |
|
|