I have been building a bill of materials tree using PHP and MySQL and have hit a wall.
I have used the following code that I found in a thread from about a year ago which is:
function build_billofmaterials($output='',$pid=0){
static $i = 1;
$level = "level".$i;
${$level} = mysql_query("select * from parts where parent = $pid") or die("Failed");
do{
$level = "level".$i;
while ($row = mysql_fetch_array(${$level})) {
if ($row[parent] != 0) {
$indent = str_repeat("--------",$i);
} else {
$indent = "";
}
$output .= $indent.$row[groupid]."-".$row[partnum]."-".$row[revision]." - ".$row[description]."<br>";
if ($row[child] = 1) {
$i++;
$pid = $row[id];
$level = "level".$i;
${$level} = mysql_query("select * from parts where parent = $pid") or die("Failed");
continue;
}
}
$i--;
if($i == 0){
break;
}
}
while(1);
echo $output;
}
build_billofmaterials();
this code displays the data perfectly in the following format:
000-000111-A - Surround Wheel Arch Front
000-000335-A - Fuel Tank Assembly Welded
000-000421-A - Group Chassis
000-000477-A - Pin Body Mount Chassis
--------000-000534-A - Bracket Bod Mount
--------000-000538-A - Bracket Assembly Body Mount
--------000-000544-A - Adaptor Fan Drive
------------000-000630-A - Cab Assembly
------------000-000641-A - Group Axle Standard 4WD
------------000-000680-A - Gusset
----------------000-000782-A - Engine Perkins Phaser 110MT
--------------------000-000802-A - Clamp Exhaust Pipe
--------------------000-000806-A - Shock Absorber Monroe
--------------------000-000836-A - Gauge Temprature VDO
----------------000-000799-A - Muffler Nelson
000-000839-A - Gauge Fuel VDO
What i need to do is for the output to only initially display the records with a parent value of 0 and then to beable to click on for example Pin Body Mount Chassis and display the parts under that and then click on say Adaptor Fan Drive and have that then display the parts under it while still keeping the previous sub category open.
The database will eventually contain around 18,000 parts so therefore it needs to function in this way to be managable
Any ideas???
Thanks