Note that there are some explanatory texts on larger screens.

plurals
  1. POphp infinite loop
    primarykey
    data
    text
    <p>This function gives me an infinite loop</p> <pre><code>function getCats($parent,$level){ // retrieve all children of $parent $result = ""; $query = "SELECT title,parent_id from t_cats where parent_id = '$parent'"; if($rs = C_DB::fetchRecordset($query)){ while($row = C_DB::fetchRow($rs)){ $result .= str_repeat($parent,$level).$row['title']."\n"; getCats($row['parent_id'],$level+1); } } return $result; } </code></pre> <p>here is my db table</p> <pre><code>CREATE TABLE `db`.`t_cats` ( `ID` int(10) unsigned NOT NULL auto_increment, `datasource_id` int(10) unsigned default '0', `version` char(10) character set latin1 default 'edit', `status` char(10) character set latin1 default 'new', `modified_date` datetime default NULL, `modified_by` int(10) unsigned default '0', `title` char(255) character set latin1 default NULL, `parent_id` int(11) default NULL, PRIMARY KEY (`ID`), KEY `idx_datasource_id` (`datasource_id`) ) ENGINE=MyISAM AUTO_INCREMENT=50 DEFAULT CHARSET=utf8; </code></pre> <p>I just want to be able to get my list of categories recursive.</p> <p>But what am i doing wrong?</p> <hr> <p><strong>EDIT:</strong></p> <pre><code>function getCats($parent,$level){ // retrieve all children of $parent $result =""; $query = "SELECT title,parent_id from t_cats where parent_id = '$parent'"; if($rs = C_DB::fetchRecordset($query)){ while($row = C_DB::fetchRow($rs)){ $result.= str_repeat($parent,$level).$row['title']."\n"; getCats($row['id'],$level + 1 ); } } return $result; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload