PHP Web Host - Quality Web Hosting For All PHP Applications Sign up for PayPal and start accepting credit card payments instantly
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 666
Location: Vancouver Island

PostPosted: Sat Nov 29, 2008 6:43 pm Reply with quote Back to top

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";
}
View user's profile Send private message
jakec
Site Admin


Joined: Feb 06, 2006
Posts: 3028
Location: United Kingdom

PostPosted: Sun Nov 30, 2008 7:57 am Reply with quote Back to top

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 />";
View user's profile Send private message
jakec
Site Admin


Joined: Feb 06, 2006
Posts: 3028
Location: United Kingdom

PostPosted: Sun Nov 30, 2008 7:58 am Reply with quote Back to top

Oh yeah obviously paste the code into the Sample Block.
View user's profile Send private message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 666
Location: Vancouver Island

PostPosted: Sun Nov 30, 2008 8:46 am Reply with quote Back to top

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:
Only registered users can see links on this board!
Get registered or login to the forums!

//
// 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";

?>

Sad
( 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


Last edited by CodyG on Sun Nov 30, 2008 9:48 am; edited 1 time in total
View user's profile Send private message
jakec
Site Admin


Joined: Feb 06, 2006
Posts: 3028
Location: United Kingdom

PostPosted: Sun Nov 30, 2008 8:52 am Reply with quote Back to top

Hmm, your image doesn't appear to be displaying.
View user's profile Send private message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 666
Location: Vancouver Island

PostPosted: Sun Nov 30, 2008 9:49 am Reply with quote Back to top

Hmm... it was looking fine for me. I put the image on another server. Is it working now?
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2404
Location: Pennsylvania

PostPosted: Sun Nov 30, 2008 12:02 pm Reply with quote Back to top

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:
Only registered users can see links on this board!
Get registered or login to the forums!

//
// 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;
}

?>
View user's profile Send private message Visit poster's website
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2404
Location: Pennsylvania

PostPosted: Sun Nov 30, 2008 12:10 pm Reply with quote Back to top

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.
View user's profile Send private message Visit poster's website
jakec
Site Admin


Joined: Feb 06, 2006
Posts: 3028
Location: United Kingdom

PostPosted: Sun Nov 30, 2008 12:55 pm Reply with quote Back to top

Cheers Palbin. Smile
View user's profile Send private message
CodyG
Life Cycles Becoming CPU Cycles


Joined: Jan 02, 2003
Posts: 666
Location: Vancouver Island

PostPosted: Sun Nov 30, 2008 1:01 pm Reply with quote Back to top

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

Countdown block now works great. Except one little thing I'd like to add ... what happens after $the_countdown_date?
View user's profile Send private message
Palbin
Site Admin


Joined: Mar 30, 2006
Posts: 2404
Location: Pennsylvania

PostPosted: Sun Nov 30, 2008 6:36 pm Reply with quote Back to top

What are you counting down? What would you like to happen?

I like to think the world will end!! ROTFL
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum