View Full Version : Resolved function error, NEED help !
auriaks
11-11-2009, 11:04 PM
Hi, i have function:
$nick = $row['Nick'];
$time = $row['time'];
$timet = date("H:i:s");
function timeDiff($firstTime,$lastTime)
{
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
}
echo "
<table width='200px';>
<tr>
<td align='center';>
<font size='0.8' face='Verdana' color='blue'><b>
$nick
</b></font>
</td>
</tr>
</table><br>
";
echo "timet: $timet <br>time: $time <br>time2: ".timeDiff($timet,$time).";<br>";
}
but somewhere is mistake which get me error: Fatal error: Cannot redeclare timediff() (previously declared in ...... Ask me if more info is neede. THANKS :)
This is most lickely because timeDiff is already used in your code. More info is needed.
auriaks
11-11-2009, 11:51 PM
<?php
include('db_conn.php');
$queryget = mysql_query("SELECT * FROM reg_users ORDER BY `time` LIMIT 10") or die("Error with query");
while ($row = mysql_fetch_array($queryget))
{
$nick = $row['Nick'];
$time = $row['time'];
$timet = date("H:i:s");
function timeDiff($firstTime,$lastTime)
{
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
}
if ($timeDiff >= -600) {
echo "
<table width='200px';>
<tr>
<td align='center';>
<font size='0.8' face='Verdana' color='blue'><b>
$nick
</b></font>
</td>
</tr>
</table><br>
";
} else {}}
?>
this is all :)
Fatal error: Cannot redeclare timediff() (previously declared in ......
Declared in what?
auriaks
11-12-2009, 12:54 AM
Fatal error: Function name must be a string in /home/freecorplietuv/domains/laisvas.xz.lt/public_html/index.php on line 238
This line is:
if ($timeDiff($timet,$time)) {
now you can see at my second script post and search for this as 238 line :)
thetestingsite
11-12-2009, 01:05 AM
move your function outside of the while loop.
Hope this helps.
Also remove the $ before timeDiff in the if statement.
auriaks
11-12-2009, 01:12 AM
still error. its working, but error is shown. now at 228.
function timeDiff($firstTime,$lastTime)
Make sure you have a starting curly bracket {.
auriaks
11-12-2009, 01:15 AM
function timeDiff($firstTime,$lastTime)
{
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
$timeDiff($timet,$time);
echo "$timeDiff";
}
if (timeDiff($timet,$time)) {
echo "
there is .
also msg is different :
Fatal error: Cannot redeclare timediff() (previously declared in /home/freecorplietuv/domains/laisvasprotas.xz.lt/public_html/index.php:228) in /home/freecorplietuv/domains/laisvasprotas.xz.lt/public_html/index.php on line 228
$timeDiff($timet,$time);
Replace with
timeDiff($timet,$time);
Paste the whole function please.
auriaks
11-12-2009, 01:17 AM
nothing changed :)
auriaks
11-12-2009, 01:18 AM
maybe function must be written differently?
[code]
Paste the whole function please.
^^ Read the whole post
auriaks
11-12-2009, 01:20 AM
<?php
include('db_conn.php');
$queryget = mysql_query("SELECT * FROM reg_users ORDER BY `time` LIMIT 10") or die("Error with query");
while ($row = mysql_fetch_array($queryget))
{
$nick = $row['Nick'];
$time = $row['time'];
$timet = date("H:i:s");
function timeDiff($firstTime,$lastTime)
{
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
timeDiff($timet,$time);
}
if (timeDiff($timet,$time)) {
echo "
<table width='200px';>
<tr>
<td align='center';>
<font size='0.8' face='Verdana' color='blue'><b>
$nick
</b></font>
</td>
</tr>
</table><br>
";
} else { }}
?>
thetestingsite
11-12-2009, 01:23 AM
Like I said before, move the function outside of the while loop like so:
<?php
include('db_conn.php');
$queryget = mysql_query("SELECT * FROM reg_users ORDER BY `time` LIMIT 10") or die("Error with query");
function timeDiff($firstTime,$lastTime) {
$firstTime=strtotime($firstTime);
$lastTime=strtotime($lastTime);
$timeDiff=$lastTime-$firstTime;
return $timeDiff;
}
while ($row = mysql_fetch_array($queryget))
{
$nick = $row['Nick'];
$time = $row['time'];
$timet = date("H:i:s");
if (timeDiff($timet,$time)) {
echo "
<table width='200px';>
<tr>
<td align='center';>
<font size='0.8' face='Verdana' color='blue'><b>
$nick
</b></font>
</td>
</tr>
</table><br>
";
} else { }}
?>
Wow... Sorry -.- I missed the function in the first post... My fault completely.
move your function outside of the while loop.
Hope this helps.
auriaks
11-12-2009, 01:26 AM
youre the man !! :D :D thanks both of you guys, really :)
Haha, it wasn't me... 0.o TheTestingSite really did it.
Please set your post to resolved by editing your first post, and changing the suffix. Good luck.
auriaks
11-12-2009, 01:29 AM
ok :D
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.