Author |
Message |
CodyG
Life Cycles Becoming CPU Cycles
![](modules/Forums/images/avatars/186c8977515afcc3ed82a.jpg)
Joined: Jan 02, 2003
Posts: 714
Location: Vancouver Island
|
Posted:
Sat Nov 29, 2008 6:43 pm |
|
I'd like to use something like this in a block.
I've tried every which way I can think of to get the output into a $content var. I've even tried using wheredoc syntax.
Basically, all it is is a function? So, how would these echos be put into a $content var?Code:
countdown(2008,12,14,12,0);
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
echo "Today's date ".date("F j, Y, g:i a")."<br />";
echo " ".date("F j, Y, g:i a",$the_countdown_date)."<br />";
echo " ".$days_left." days ".$hours_left." hrs ".$minutes_left." mins";
}
|
|
_________________ "We want to see if life is ubiquitous." D.Goldin |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
jakec
Site Admin
![](modules/Forums/images/avatars/502a2d1345d88a86ddb4a.png)
Joined: Feb 06, 2006
Posts: 3048
Location: United Kingdom
|
Posted:
Sun Nov 30, 2008 7:57 am |
|
Try commenting out the echo's and add the $content outside of the function. For instance the first echo would be:
Code:$content .= "Today's date ".date("F j, Y, g:i a")."<br />";
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
jakec
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 7:58 am |
|
Oh yeah obviously paste the code into the Sample Block. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 8:46 am |
|
That was the first thing I tried. But I'll try it again.
Code:<?php
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
// countdown function
// parameters: (year, month, day, hour, minute)
$content = '';
countdown(2008,12,14,12,0);
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
//echo "Today's date ".date("F j, Y, g:i a")."<br/>";
//echo " ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
//echo " ".$days_left." days ".$hours_left." hrs ".$minutes_left." mins";
}
$content .= "Today's date ".date("F j, Y, g:i a")."<br/>";
$content .= " ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
$content .= " ".$days_left." days ".$hours_left." hrs ".$minutes_left." mins";
?>
|
( What are those other values i (0, and -1) in the mktime function? And why is the var order different than the function call? )
This is the result ....
![Image Image](http://members.shaw.ca/catherin/images/countdown2.jpg) |
Last edited by CodyG on Sun Nov 30, 2008 9:48 am; edited 1 time in total |
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
jakec
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 8:52 am |
|
Hmm, your image doesn't appear to be displaying. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 9:49 am |
|
Hmm... it was looking fine for me. I put the image on another server. Is it working now? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
Site Admin
![](modules/Forums/images/avatars/Dilbert/Dilbert_-_Dogbert_King.gif)
Joined: Mar 30, 2006
Posts: 2583
Location: Pittsburgh, Pennsylvania
|
Posted:
Sun Nov 30, 2008 12:02 pm |
|
Variables do not come out of functions for the most part unless you return them.
The content variable in the function could have been named anything.
Code:
<?php
if ( !defined('BLOCK_FILE') ) {
Header("Location: ../index.php");
die();
}
//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
// countdown function
// parameters: (year, month, day, hour, minute)
if (empty($content)){$content = '';}
$content .= countdown(2008,12,14,12,0);
function countdown($year, $month, $day, $hour, $minute)
{
// make a unix timestamp for the given date
$the_countdown_date = mktime($hour, $minute, 0, $month, $day, $year, -1);
// get current unix timestamp
$today = time();
$difference = $the_countdown_date - $today;
if ($difference < 0) $difference = 0;
$days_left = floor($difference/60/60/24);
$hours_left = floor(($difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($difference - $days_left*60*60*24 - $hours_left*60*60)/60);
// OUTPUT
//echo "Today's date ".date("F j, Y, g:i a")."<br/>";
//echo " ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
//echo " ".$days_left." days ".$hours_left." hrs ".$minutes_left." mins";
$content = "Today's date ".date("F j, Y, g:i a")."<br/>";
$content .= " ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
$content .= " ".$days_left." days ".$hours_left." hrs ".$minutes_left." mins";
return $content;
}
?>
|
|
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 12:10 pm |
|
Look up mktime() at the php site. It will tell you what all the variables are for.
Note: if you have php 5.1 or greater the last variable has become deprecated. |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
jakec
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 12:55 pm |
|
Cheers Palbin. ![Smile](modules/Forums/images/smiles/icon_smile.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
CodyG
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 1:01 pm |
|
Quote: | Variables do not come out of functions for the most part unless you return them. |
You rock! I've been trying to understand that concept in programming nuke for a long, long time. So many functions, so few returns.
Countdown block now works great. Except one little thing I'd like to add ... what happens after $the_countdown_date? |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
Palbin
![](modules/Forums/images/avatars/gallery/blank.gif)
|
Posted:
Sun Nov 30, 2008 6:36 pm |
|
What are you counting down? What would you like to happen?
I like to think the world will end!! ![ROTFL](modules/Forums/images/smiles/rotfl.gif) |
|
|
|
![](themes/RavenIce/forums/images/spacer.gif) |
|