To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
Code CritiqueHaving someone critique your code is always a great way to hone the skills. Stop in and post your code to see what your peers may have done differently.
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
Quote:
Originally posted by Moonglobe and it'd be nice to be able to specify what character to use instead of "*" all the time...
Like, select the fields you actually want?
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
Location: Rapid Offensive Unit "Foreign Object Damage"
Posts: 19,122
Quote:
Originally posted by Moonglobe that'd be nice too, but i meant that you could use different chars for indenting.... maybe per-level if you passed an array, so it would rotate.
More flexible perhaps, a <span> style based on the depth of node ( "treelevel1", "treelevel2", ... etc.).
__________________
On two occasions I have been asked [by Members of Parliament], "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.
I was bored so attached you'll find a script that will test to see if your environment can run and the script and if not configure your environment to do so.
the changes are listed here:
PHP Code:
/* CHANGE LOG
0) Changed _parent column to parent column - I made a boo boo on table creation
and this change was easier then that fix.
1) Add parameter $idnt to allow the user to specify indentation
2) Changed default $cnt to 0 so that user is not forced into having an
indent on the root level
3) added mysql_free_result to clean up after self
4) added parameter checking
a) added parameter $running so we know if we have to do parameter checking
5) return an array instead of echoing the tree to allow more flexibility
*/
function buildTree($id = 0, $cnt = 0, $idnt = '*', $running = 0) {
//if we are not in a recursive loop
if(!$running || !is_numeric($running)) {
if(!is_numeric($id)) {return -1;}
if(!is_numeric($cnt)) {return -1;}
if(!is_numeric($cnt)) {return -1;}
} //end if
$retVal = array();
$query = "SELECT * FROM names WHERE parent = ". $id;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
array_push($retVal,(str_repeat($idnt,$cnt) . $row['name']));
$retVal = array_merge($retVal,buildTree($row['id'], $cnt + 1,$idnt,1));
}
mysql_free_result($result);
return($retVal);
} //end build tree
Originally posted by thoand Thanks for the interest,
but one question,
I thought mysql_free_result had no effect anymore, that PHP always cleans up.
Thomas
PHP frees results when script execution has ended, mysql_free_result() can free up the memory beforehand, useful if you have a huge recordset slowing everything down.