Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts

    function parameters not getting spat out...

    ok...

    so i have a variable...
    PHP Code:
    $iSqlNumQuery 0
    at the top of my page...about my functions..

    i have a function, which has a query in it, so i want it counted...

    PHP Code:
    functionName ($iSqlNumQuery) {
    //do all my query stuff, echo stuff to page...works fine
    $iSqlNumQuery++;
    return 
    $iSqlNumQuery;

    now...

    it wont increment my variable...could someone possibly shed some light on this...

    Thanks, Justin

  • #2
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    how are you calling the function.
    you need to have the function call like this
    PHP Code:

    $iSqlNumQuery 
    functionName($iSqlNumQuery);


    function 
    functionName ($iSqlNumQuery) {
    //do all my query stuff, echo stuff to page...works fine
    $iSqlNumQuery++;
    return 
    $iSqlNumQuery;


  • #3
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MRMAN
    how are you calling the function.
    you need to have the function call like this
    PHP Code:

    $iSqlNumQuery 
    functionName($iSqlNumQuery);


    function 
    functionName ($iSqlNumQuery) {
    //do all my query stuff, echo stuff to page...works fine
    $iSqlNumQuery++;
    return 
    $iSqlNumQuery;

    oh okies
    Last edited by jussa; 05-02-2006 at 12:46 PM.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    or use static variables:
    PHP Code:
    function counter() {
        static 
    $iSqlNumQuery;
        
    $iSqlNumQuery++;
        return 
    $iSqlNumQuery;
    }

    $variable=counter(); 

  • #5
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    wait, nope...

    this is how i call my function...like u said...

    PHP Code:
    $iSqlQueryCount addHit($iSqlQueryCount); 
    this is the actual function...
    PHP Code:
    function countHits($QueryCount) {
        
    $query "SELECT hit_ip, hit_datecode FROM jet3_hits";
        
    $result mysql_query($query) or die(mysql_error());
        
    $numrows mysql_num_rows($result);
        echo 
    $numrows;
        
    $QueryCount++;
        return 
    $QueryCount;

    but it still does not return an incremented value...

    Thanks, Justin

  • #6
    Regular Coder
    Join Date
    Jan 2006
    Location
    Preston, Lancashire, England
    Posts
    285
    Thanks
    0
    Thanked 0 Times in 0 Posts
    PHP Code:
    $counter 0;
    print 
    "counter = " $counter "<BR>";    
    $counter incounter($counter);
    print 
    "counter = " $counter "<BR>";

    function 
    incounter($counterr)
    {
        
    $counterr++;
        return 
    $counterr;

    the code above prints off
    counter = 0
    counter = 1

    but its probably a miss type but in your last post there are two different functions being used

  • #7
    Regular Coder
    Join Date
    Mar 2006
    Posts
    120
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by MRMAN
    PHP Code:
    $counter 0;
    print 
    "counter = " $counter "<BR>";    
    $counter incounter($counter);
    print 
    "counter = " $counter "<BR>";

    function 
    incounter($counterr)
    {
        
    $counterr++;
        return 
    $counterr;

    the code above prints off
    counter = 0
    counter = 1

    but its probably a miss type but in your last post there are two different functions being used
    yer, but both have the increment in it...and nothing is getting incremented...so the return isnt working... also, should that be last line in the function...
    PHP Code:
    return $variable
    Thanks, Justin


  •  

    Posting Permissions

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