Welcome, Guest. Please login or register.
February 11, 2025, 03:56:17 am
Home Help Search Calendar Login Register
News: Brian Fein is now blogging weekly!  Make sure to check the homepage for his latest editorial.
+  The Dolphins Make Me Cry.com - Forums
|-+  TDMMC Forums
| |-+  Off-Topic Board
| | |-+  TDMMC Programming Help
« previous next »
Pages: [1] Print
Author Topic: TDMMC Programming Help  (Read 1742 times)
Dave Gray
Administrator
Uber Member
*****
Posts: 30897

It's doo-doo, baby!

26384964 davebgray@comcast.net davebgray floridadavegray
WWW Email
« on: November 04, 2008, 02:08:40 pm »

Nerds, I have a small issue.  I know some of you write little programs in your spare time.  If you're up for it, I've got something for you.

On the TDMMC homepage, there's a little image for "next up" and shows the upcoming logo for the team we're going to play.

Unfortunately, I suck at updating it.  It only takes about 10 minutes, but it's the last thing I have time to do on Monday morning, when client calls and emails are rolling in.  Is is possible to write a script that looks at the date/time, and then displays the appropriate logo?

Something like:

If date is between 10/7-10/14, then show the Pats
If date is between 10/15-10 21, then show the Bills
....and so on.


Then, I'd only have to do one substantial update of that file, once per year.
Logged

I drink your milkshake!
fyo
Uber Member
*****
Posts: 7545


4866.5 miles from Dolphin Stadium


« Reply #1 on: November 04, 2008, 05:12:21 pm »

Sure... assuming php:

Database:

table: gameschedule


**************************************************
* date     * opponent * location * teamgraphic   *
**************************************************
* 20080907 * Jets      * home    * jets.png      *
* 20080914 * Cardinals * away    * cardinals.png *
* 20080921 * Patriots  * away    * patriots.png  *
* 20081005 * Chargers  * home    * chargers.png  *

[...]


Code to stick in the appropriate php file:


$today = date("Ymd"); // set the variable $today equal to the todays date in the format specified (YYYYMMDD, e.g. 20081104)
$sql = "SELECT * FROM gameschedule WHERE kickoff>$today ORDER BY kickoff DESC LIMIT 1"; // get the first game in the future.
$result = mysql_query($sql); // assumes active connection to the database with the gameschedule table.
if ($result) {
  if ($myrow = mysql_fetch_array($result)) {
    $kickoff = $myrow['kickoff']; // get the appropriate contents of the database row and stick it in a variable...
    $location = $myrow['location'];
    $opponent = $myrow['opponent'];
    $teamgraphic = $myrow['teamgraphic'];
  } else {
    // OK, no row was returned from the database. Let's assume it's off season then ;-)
    $kickoff = "";
    $location = "";
    $opponent = "";
    $teamgraphic = "offseason.png"; // let's have an off season pic!
  }
} else {
  // a database error occurred. Even if there is no matching game, a non-empty $result should still be returned.
  // at this point, I'm just ignoring it. Yes, I'm being lazy. Most likely case: the table doesn't exist.
  // echo mysql_error(); exit; // uncomment this line if you want the error msg that was likely generated.
}


In the appropriate place in your php file, where you currently have this bit:


<td><div align="center"> <img src="images/logos/patriots.gif" width="90" height="42">



You'll want to insert the the image name provided by the script above. Done in ugly inline scripting (I don't know if you are using template files or what), you would just write:


<td><div align="center"> <img src="images/logos/<?php echo $teamgraphic ?>" width="90" height="42">



And similar for the date. Although, you'll note I didn't actually include the kickoff time in my example... Wink. Personally, I tend to use UNIX timestaps for dates, but it might be more intuitive to just expand the format I used above with "military time", e.g. 200809071300 for the 1pm Jets game in week 1. (No ZULU time here... UNIX timestamps use it, though!).
Logged
Dave Gray
Administrator
Uber Member
*****
Posts: 30897

It's doo-doo, baby!

26384964 davebgray@comcast.net davebgray floridadavegray
WWW Email
« Reply #2 on: November 04, 2008, 05:35:39 pm »

Oh great.  You broke my brain.

Fau, can you implement this?
Logged

I drink your milkshake!
fyo
Uber Member
*****
Posts: 7545


4866.5 miles from Dolphin Stadium


« Reply #3 on: November 04, 2008, 06:10:29 pm »

Two comments:

The above is missing a bit to format the date / time. I didn't include time initially, because kickoff times are subject to change... so you'd have to go at "fix them" every once in a while - although probably not more than a few times a season.

PHP has several built-in functions to format a date how you want it. It does like to get the "input date" in UNIX format (which is the number of seconds since Jan 1, 1970). The problem here is just that if you want to input the dates / times manually, UNIX format isn't exactly the "friendly" option.

Probably the easiest thing to do is quickly convert from your chosen time to UNIX time and then format as you want. The function "mktime" does exactly that.


// assume date/time format: 200809071300 (i.e. YYYYMMDDHHMM)
$year = substr($kickoff,0,4); // year is first for characters of $kickoff variable... characters numbered 0,1,2 and 3
$month = substr($kickoff,4,2); // month is in the next two, numbered 4 and 5.
$day = substr($kickoff,6,2); // day is the next two, numbered 6 and 7.
$hour = substr($kickoff,8,2); // hour ...
$minute = substr($kickoff,10,2); // minute
$second = 0; // we're not that precise!
$kickoffinunixtime = mktime($hour, $minute, $second, $month, $day, $year);


Then in the place where you want the date/time to appear, you insert (cf. teamgraphic example) :


<?php echo date("F j, g:i A",$kickoffinunixtime); ?>


(the strange "F j, g:i A" just tells php to format the time as is currently done on the thedolphinsmakemecry.com site, i.e. Month, 12-hour-time-without-leading-zero:minutes-with-leading-zero AM/PM-as-appropriate).

I'd be happy to give Fau a hand. Feel free to pm me.

EDIT: Oh, and the second comment... The "location" and "opponent" stuff isn't used right now...  and then there's the bit about.. A test for the case of kickoff = 0 should also be included for the case where no game was found (i.e. probably off season).
« Last Edit: November 04, 2008, 06:15:58 pm by fyo » Logged
fyo
Uber Member
*****
Posts: 7545


4866.5 miles from Dolphin Stadium


« Reply #4 on: November 04, 2008, 06:31:40 pm »

If you don't want to enter the data directly into the database, a text-file uploaded to a specific place on the server would work as well. Rewriting for that would be simple (but I'm not going to do it unless that's what you need).
Logged
Fau Teixeira
Administrator
Uber Member
*****
Posts: 6343



« Reply #5 on: November 04, 2008, 10:35:06 pm »

it's a 16 game season .. no reason why we can't just set up a simple array  and use the date() function in php for this
Logged
fyo
Uber Member
*****
Posts: 7545


4866.5 miles from Dolphin Stadium


« Reply #6 on: November 05, 2008, 12:54:22 am »

it's a 16 game season .. no reason why we can't just set up a simple array  and use the date() function in php for this

It's all a question of where you are comfortable having Mr. Grey sticking his paws Wink
A text file might be more unintrusive and "simpler".
Coding wouldn't be harder, a few lines to read in the file. Don't really even need to fully construct the array, although you could have an array for the images predefined in straight php.
Logged
Pages: [1] Print 
« previous next »
Jump to:  

The Dolphins Make Me Cry - Copyright© 2008 - Designed and Marketed by Dave Gray


Powered by SMF 1.1.21 | SMF © 2015, Simple Machines