Site Links
Home
Features
Documentation
Pricing & Order
Members Area
Support Options
UBBDev.com
UBBWiki.com
Who's Online
2 registered (Ruben, Gizmo), 22 Guests and 4 Spiders online.
Key: Admin, Global Mod, Mod
Featured Member
Registered: 12/29/03
Posts: 2020
Top Posters (30 Days)
Ruben 47
Bert 26
Gizmo 18
Rob Provencher 10
Rimex 9
SD 6
sw55 5
Eugene 5
Matthias1976 4
Dunny 3
Latest Photos
Uhm...
Mayan End of World
Gas Station Disco Video Shoot
Test Pictures
Audrey Kate
Page 1 of 3 1 2 3 >
Topic Options
#205976 - 02/04/08 04:22 PM PHP Coding Help?
jgeoff Offline
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 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:

Code:
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
Express Hosting "We are the official hosting company of UBB.threads. Ask us about our free migration services to migrate your UBB.threads installation."
#206263 - 02/11/08 12:39 PM Re: PHP Coding Help? [Re: jgeoff]
AllenAyres Offline

Registered: 12/29/03
Posts: 2020
Loc: Texas
Anyone?

Buehler?

smile
_________________________
- Allen
- ThreadsDev | PraiseCafe
Top
#206277 - 02/11/08 02:31 PM Re: PHP Coding Help? [Re: AllenAyres]
jgeoff Offline
Pooh-Bah
Registered: 08/08/06
Posts: 1931
Loc: NJ

Thanks for resurrecting this. smile

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 laugh )
Quote:

Airing today is quite easy - you just need to use the PHP date function. Something like:
Code:
$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:
Code:
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. wink

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. blush

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
#206297 - 02/12/08 03:55 AM Re: PHP Coding Help? [Re: jgeoff]
Mark S Offline
Carpal Tunnel
Registered: 07/04/06
Posts: 4480
Loc: Liverpool : England : UK
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.
_________________________
Version v7.5.6 smile smile < Threads satisfaction status
People who inspire me Rick Gizmo Ian David jgeoff ntdoc
Oooo i hear 8 is coming? just after 7 my friend.
Top
#206298 - 02/12/08 05:02 AM Re: PHP Coding Help? [Re: Mark S]
Gizmo Online   cat

Registered: 06/05/06
Posts: 15455
Loc: Portland, OR; USA
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)
_________________________
Forums: UGN Security & VNC Web Design & Development
UBB.Threads: UBB.Wiki, My UBBSkins, UBB.Sitemaps
Longtime Supporter, Beta Tester & Resident Post-A-Holic.
Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Top
#206602 - 02/17/08 01:58 PM Re: PHP Coding Help? [Re: Mark S]
jgeoff Offline
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! blush )

Php Code:

$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");  // month n (1-12) day j (1-31)
echo $today;		  // just making sure data is as entered

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 wink


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
#206604 - 02/17/08 02:13 PM Re: PHP Coding Help? [Re: jgeoff]
Mark S Offline
Carpal Tunnel
Registered: 07/04/06
Posts: 4480
Loc: Liverpool : England : UK
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.
_________________________
Version v7.5.6 smile smile < Threads satisfaction status
People who inspire me Rick Gizmo Ian David jgeoff ntdoc
Oooo i hear 8 is coming? just after 7 my friend.
Top
#206605 - 02/17/08 02:35 PM Re: PHP Coding Help? [Re: Mark S]
jgeoff Offline
Pooh-Bah
Registered: 08/08/06
Posts: 1931
Loc: NJ
Originally Posted By: Mark S
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) blush

Thanks for making me look at it more closely -- it works now! wink
_________________________
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]
jgeoff Offline
Pooh-Bah
Registered: 08/08/06
Posts: 1931
Loc: NJ

After many new errors, I got it working in a custom island!! Woohoo!! smile

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 laugh

Thanks, Mark cool
_________________________
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
#206628 - 02/18/08 01:51 AM Re: PHP Coding Help? [Re: jgeoff]
jgeoff Offline
Pooh-Bah
Registered: 08/08/06
Posts: 1931
Loc: NJ

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.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
Page 1 of 3 1 2 3 >



Moderator:  AllenAyres, Harold, Ian, Ron M 
Shout Box

Today's Birthdays
No Birthdays
Recent Topics
Time zone setup
by skicomau
05/22/13 12:16 AM
Express hosting.
by Ruben
05/16/13 03:54 PM
Level of detail in new user registration emails
by Mitch P.
05/15/13 10:20 PM
Approving users
by Bert
05/15/13 09:22 PM
Users randomly added to other group
by Bert
05/15/13 09:15 PM
Forum Stats
10969 Members
36 Forums
33959 Topics
183413 Posts

Max Online: 978 @ 06/24/07 10:19 PM
Random Image