Page 1 of 2 12 LastLast
Results 1 to 10 of 20

Thread: function error, NEED help !

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default function error, NEED help !

    Hi, i have function:
    PHP Code:
    $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&nbsp;
            </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
    Last edited by auriaks; 11-12-2009 at 01:29 AM.

  2. #2
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    This is most lickely because timeDiff is already used in your code. More info is needed.
    Jeremy | jfein.net

  3. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    PHP Code:
    <?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&nbsp;
            </b></font>
            </td>
            </tr>
        </table><br>
        "

    } else {}}  

    ?>
    this is all

  4. #4
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Code:
    Fatal error: Cannot redeclare timediff() (previously declared in ......
    Declared in what?
    Jeremy | jfein.net

  5. #5
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    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:
    PHP Code:
     if ($timeDiff($timet,$time)) { 
    now you can see at my second script post and search for this as 238 line

  6. #6
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    move your function outside of the while loop.

    Hope this helps.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  7. #7
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Also remove the $ before timeDiff in the if statement.
    Jeremy | jfein.net

  8. #8
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    still error. its working, but error is shown. now at 228.
    PHP Code:
        function timeDiff($firstTime,$lastTime

  9. #9
    Join Date
    Jan 2008
    Posts
    4,168
    Thanks
    28
    Thanked 628 Times in 624 Posts
    Blog Entries
    1

    Default

    Make sure you have a starting curly bracket {.
    Jeremy | jfein.net

  10. #10
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    PHP Code:
    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 :
    PHP Code:
    Fatal errorCannot redeclare timediff() (previously declared in /home/freecorplietuv/domains/laisvasprotas.xz.lt/public_html/index.php:228in /home/freecorplietuv/domains/laisvasprotas.xz.lt/public_html/index.php on line 228 

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •