Jump to content
php.lv forumi

function pats uz sevi


reiniger

Recommended Posts

Sveiki.

 

Kaut kā pašam neizdodas rast risinājum.

 

Būtība man nepieciešams iegūt child ja nav, tad tmpid un ja nav norādīts šims ID, tad meklē to parent id turpinot kokam virzoties uz augšu.

 

function getSome($id){

$sql = "SELECT d.* ";
$sql .= "FROM obj AS d ";
$sql .= "WHERE d.id = {$id} ";

$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);

if($row['child'] && $row['tmpid']){
	 if($row['child']){
		 echo $row['child'];
		 return $row['child'];
	 }elseif($row['tmpid'])
		 return $row['tmpid'];
}else{
 getSome($row['parent']);
}

}

Pieļauju ka ir kaut kāda neprecizitāte kas pēc kārtas izpildās. Jo ir tā ka echo man izvada manu nepieciešamo ID, bet return neko neatgriež.

Link to comment
Share on other sites

Atrisināju pats:

 

function getSome($id){
$sql = "SELECT d.* ";
$sql .= "FROM obj AS d ";
$sql .= "WHERE d.id = {$id} ";
$result = mysql_query($sql);
$row = mysql_fetch_assoc($result);
if($row['child'] || $row['tmpid']){
			 if($row['child']){
					 return $row['child'];
			 }elseif($row['tmpid'])
					 return $row['tmpid'];
}else{
$ids = getSome($row['parent']);
return $ids;
}
}

Edited by reiniger
Link to comment
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...