Page 1 of 1

problem with return in a function

Posted: Sun Aug 18, 2002 6:26 pm
by peppelorum
Having trouble to return a value from a function. Just before I try to return I print out the variable to see if it contains anything, and it does that every time. Calls the function with $thread = back($row[0]);
Anyone with a clue?

Code: Select all

function back($id)
{

	global $db;
	
	$sql = "SELECT eforum_reply,eforum_id ".
	"FROM eforum ".
	"WHERE eforum_id = ".$id."";
	
	$result = mysql_query($sql,$db);
	if( mysql_error() ) { die(mysql_error());}
	
	while($row2 = mysql_fetch_row($result))
	{
	
		if($row2ї0] != 0) back($row2ї0]);
		else $tagg = $row2ї1];
	
	}
	
	echo($tagg);
	return $tagg;

}

Posted: Sun Aug 18, 2002 9:23 pm
by phpPete
Since it echos a value for you in your function then it's your query string.

You're concatenation is a little funky.

Try this:

Code: Select all

$sql = "SELECT eforum_reply, eforum_id FROM eforum WHERE eforum_id = ". $id;
How do you have register globals set in you php.ini? Looks like it's set to on. if it's set to off, and it should be, you need to access the value via the super global arrays $_GET, $_POST for php 4.2.0 ++.
Or $HTTP_GET_VARS, $HTTP_POST_VARS for pre 4.2.0


"Quote the constants and concatenate the variables"

Posted: Mon Aug 19, 2002 1:45 am
by peppelorum
yes I know the " " on the end of sql-string was strange:) but no It doesnt work what you said.

since I send $id to the function when I calls it means that register globals is not involved here, echos the $id in the beginning of the function and it is always correct.

Posted: Mon Aug 19, 2002 1:52 am
by peppelorum
have found that it´s the while that makes the trouble.. is it possible to check the value in the db without a while?

Posted: Mon Aug 19, 2002 5:48 am
by phpPete
Put this in your while loop.


Code: Select all

echo "Value of $row&#1111;0] is: <br>" . $row&#1111;0];
And what do you see?

Posted: Mon Aug 19, 2002 7:49 am
by fatalcure
try !== instead of !=

Posted: Mon Aug 19, 2002 9:29 am
by mikeq
fatalcure wrote:try !== instead of !=
It's not !== it is !=

so is that a not not :lol:

Posted: Mon Aug 19, 2002 9:33 am
by peppelorum
solved it by changing in the while, but thanks for the effort:)

Code: Select all

while($row2 = mysql_fetch_row($result)) 
&#123; 
  
   if($row2&#1111;0] != 0) $tagg = back($row2&#1111;0]); 
   else $tagg = $row2&#1111;1]; 
    
&#125;

Posted: Mon Aug 19, 2002 9:51 am
by fatalcure
i coulda sworn it was !== and not != ... maybe u can use both?

Posted: Mon Aug 19, 2002 9:56 am
by phpPete

Code: Select all

$sentiment = "I hate recursive functions!";
while( earth revolves around the sun )
    &#123;
          echo $sentiment . "<br>\n";
    &#125;

Posted: Mon Aug 19, 2002 10:05 am
by llimllib
!== means, more or less, 'exactly not equals to', while != means 'not equals to'

$var = 5;

if($var != true)
//doesn't get here: 5 is 'equal to' true

if($var !== true)
//gets here: 5 is not 'exactly equal to' true (because they're
//not of the same type; boolean vs. integer)

check out the manual for a better description