...

View Full Version : Problems with strings...



gsnedders
05-12-2004, 06:54 PM
Look at http://f1unleashed.geoffers.uni.cc/circuits.php?race=monaco

The line of the script is
countdown("print $strYear","print $strMonth","print $strDay","print $strHour","print $strMinute");

In the page it has
$strYear = '2004';
$strMonth = '5';
$strDay = '23';
$strHour = '5';
$strMinute = '0';

bcarl314
05-12-2004, 07:28 PM
Can you post the countdown function code?

gsnedders
05-12-2004, 08:08 PM
<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown("print $strYear","print $strMonth","print $strDay","print $strHour","print $strMinute");

//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
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 "Countdown date ".date("F j, Y, g:i a",$the_countdown_date)."<br/>";
echo "Countdown ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>

bcarl314
05-12-2004, 08:10 PM
I see, try this...



countdown($strYear,$strMonth,$strDay,$strHour,$strMinute);



If you're passing variables to a function, you don't need to "print" them in the parameter list, just type the vars in straight.

<edit>
Shouldn't be a space in strMinute. Can't seem to fix the post.
</edit>

gsnedders
05-12-2004, 08:23 PM
Thanks but is there anyway from stopping it saying:
Countdown: 0 days 0 hours 0 minutes left The code now is
<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown($strYear,$strMonth,$strDay,$strHour,$strMinute);

//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
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 "Countdown: ".$days_left." days ".$hours_left." hours ".$minutes_left." minutes left";
}
?>

raf
05-12-2004, 09:04 PM
I don't see a problem, so i ran the code and it seems to work.
(I got : Countdown: 10 days 6 hours 49 minutes left)

Though i wouldn't do the if ($difference < 0) $difference = 0;
like that.
If difference <0 , then i would take the absolute value (abs()) and then print something like " x was ... days ... hours ... minutes ago"

gsnedders
05-12-2004, 09:56 PM
I don't see a problem, so i ran the code and it seems to work.
(I got : Countdown: 10 days 6 hours 49 minutes left)

Though i wouldn't do the if ($difference < 0) $difference = 0;
like that.
If difference <0 , then i would take the absolute value (abs()) and then print something like " x was ... days ... hours ... minutes ago"

How (my knowledge of PHP is still very limited)?

raf
05-12-2004, 10:20 PM
$difference = $the_countdown_date - $today;
$absolute_difference = abs($difference);

$days_left = floor($absolute_difference/60/60/24);
$hours_left = floor(($absolute_difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($absolute_difference - $days_left*60*60*24 - $hours_left*60*60)/60);

// OUTPUT
if ($difference != $absolute_difference){
$output= 'The event was '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' ago !';
} else {
$output= 'Countdown: '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' minutes left.';
}
echo $output;

gsnedders
05-13-2004, 06:36 PM
Still showing errors, code now is:

<?php
// countdown function
// parameters: (year, month, day, hour, minute)
countdown($strYear,$strMonth,$strDay,$strHour,$strMinute);

//--------------------------
// author: Louai Munajim
// website: www.elouai.com
//
// Note:
// Unix timestamp limitations
// Date range is from
// the year 1970 to 2038
//--------------------------
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;
$absolute_difference = abs($difference);

$days_left = floor($absolute_difference/60/60/24);
$hours_left = floor(($absolute_difference - $days_left*60*60*24)/60/60);
$minutes_left = floor(($absolute_difference - $days_left*60*60*24 - $hours_left*60*60)/60);

// OUTPUT
if ($difference != $absolute_difference){
$output= 'The event was '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' ago !';
} else {
$output= 'Countdown: '.$days_left.' days '.$hours_left.' hours '.$minutes_left.' minutes left.';
}
echo $output;
}
?>





:mad: What's it done... Fixed



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum