Jump to content

function recursion HELP!!


MDanz

Recommended Posts

the function keeps returning 1. if i echo $i within the function then it counts up to six.  the function should return 6, because there are 6 results from the mysql_query, so $i iterates upto 6.  please any help solving this?

 

$i=0;

$thewidth = $database->width($theid, $i);

echo $thewidth;

 

function width($theid,$i)
{
$get =  mysql_query("SELECT * FROM block WHERE sid='$theid'",$this->connect);

$i++;		

while($row = mysql_fetch_assoc($get)) {


$number = $row['id'];

$this->width($number, $i);

return $i;	 

	}  


}

Link to comment
Share on other sites

the variable in the WHERE clause is the result of that WHERE clause. if that sounds confusing. basically the next result in the query is dependent on the previous result.  If i used a while loop then i would have to keep on repeating the while loop for every result.  With function recursion it repeats it for me.

 

unless you know a better way than function recursion to loop the below so the result($number) of the query is inputted back into the WHERE clause and repeated.

$get =  mysql_query("SELECT * FROM block WHERE sid='$number'",$this->connect);

while($row = mysql_fetch_assoc($get)) {


$number = $row['id'];
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.