Previous Thread
Next Thread
Print Thread
Hop To
#205976 02/04/2008 6:22 PM
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 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.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
jgeoff #206263 02/11/2008 2:39 PM
Joined: Dec 2003
Posts: 1,796
Pooh-Bah
Pooh-Bah
Joined: Dec 2003
Posts: 1,796
Anyone?

Buehler?

smile


- Allen
- ThreadsDev | PraiseCafe
Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1

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.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
jgeoff #206297 02/12/2008 5:55 AM
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
Mark S #206298 02/12/2008 7:02 AM
Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
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)


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Mark S #206602 02/17/2008 3:58 PM
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! 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

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
jgeoff #206604 02/17/2008 4:13 PM
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
Mark S #206605 02/17/2008 4:35 PM
Joined: Aug 2006
Posts: 1,649
Likes: 1
Pooh-Bah
Pooh-Bah
Joined: Aug 2006
Posts: 1,649
Likes: 1
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.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
jgeoff #206612 02/17/2008 6:39 PM
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!! 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.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
jgeoff #206628 02/18/2008 3:51 AM
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
jgeoff #206703 02/18/2008 4:57 PM
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 wink


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Mark S #206707 02/18/2008 5:09 PM
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 wink

Hey, if yours isn't working post it here now that I'm a Big Expert! laugh laugh (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
jgeoff #206710 02/18/2008 5:17 PM
Joined: Jul 2006
Posts: 4,057
Joined: Jul 2006
Posts: 4,057
lol

no mines working but not in a content island
its screwing up my forums and strange things.

https://www.ubbcentral.com/forums/ubbthreads.php/topics/206237/7_2_2_Custom_Island.html#Post206237

it will work as expected in a header or introduction
but not a content island. ???


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Mark S #206743 02/19/2008 12:29 AM
Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
Likes: 116
i helped someone do this before; but I forget who it was...


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Gizmo #206751 02/19/2008 4:52 AM
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
Gizmo #206788 02/19/2008 1:57 PM
Joined: Jul 2006
Posts: 4,057
Joined: Jul 2006
Posts: 4,057
Originally Posted by Gizmo
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
Mark S #206800 02/19/2008 2:35 PM
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. frown Why would it not do it automatically? confused 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
jgeoff #206801 02/19/2008 3:59 PM
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 wink


BOOM !! Version v7.6.1.1
People who inspire me Isaac ME Gizmo
Mark S #206824 02/19/2008 8:22 PM
Joined: Jun 2006
Posts: 16,299
Likes: 116
UBB.threads Developer
UBB.threads Developer
Joined: Jun 2006
Posts: 16,299
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...


I am a Web Development Contractor, I do not work for UBBCentral. I have provided free User to User Support since the beginning of these support forums.
Do you need Forum Install or Upgrade Services?
Forums: A Gardeners Forum, Scouters World
UBB.threads: UBBWiki, UBB Styles, UBB.Sitemaps
Longtime Supporter & Resident Post-A-Holic
VNC Web Services: Code Modifications, Upgrades, Styling, Coding Services, Disaster Recovery, and more!
Gizmo #206837 02/19/2008 11:27 PM
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 cool


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
jgeoff #206839 02/20/2008 1:41 AM
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

Link Copied to Clipboard
ShoutChat
Comment Guidelines: Do post respectful and insightful comments. Don't flame, hate, spam.
Recent Topics
Bots
by Outdoorking - 04/13/2024 5:08 PM
Can you add html to language files?
by Baldeagle - 04/07/2024 2:41 PM
Do I need to rebuild my database?
by Baldeagle - 04/07/2024 2:58 AM
This is not a bug, but a suggestion
by Baldeagle - 04/05/2024 11:25 PM
Is UBB.threads still going?
by Aaron101 - 04/01/2022 8:18 AM
Who's Online Now
1 members (Nightcrawler), 718 guests, and 210 robots.
Key: Admin, Global Mod, Mod
Random Gallery Image
Latest Gallery Images
Los Angeles
Los Angeles
by isaac, August 6
3D Creations
3D Creations
by JAISP, December 30
Artistic structures
Artistic structures
by isaac, August 29
Stones
Stones
by isaac, August 19
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20240501)