...

View Full Version : function parameters not getting spat out...



jussa
05-02-2006, 11:54 AM
ok...

so i have a variable...
$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...


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

MRMAN
05-02-2006, 12:03 PM
how are you calling the function.
you need to have the function call like this



$iSqlNumQuery = functionName($iSqlNumQuery);


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

jussa
05-02-2006, 12:14 PM
how are you calling the function.
you need to have the function call like this



$iSqlNumQuery = functionName($iSqlNumQuery);


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


oh okies

GJay
05-02-2006, 12:20 PM
or use static variables:


function counter() {
static $iSqlNumQuery;
$iSqlNumQuery++;
return $iSqlNumQuery;
}

$variable=counter();

jussa
05-02-2006, 12:46 PM
wait, nope...

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


$iSqlQueryCount = addHit($iSqlQueryCount);

this is the actual function...

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

MRMAN
05-02-2006, 12:59 PM
$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

jussa
05-02-2006, 11:59 PM
$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...
return $variable;

Thanks, Justin



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum