Forum Moderators: coopster
Each subcategory is stored in a table with the following fields:
id, section, category, previous_subcategory, subcategory, rank
A subcategory named 'state_parks' would be stored as:
99 ¦ recreation ¦ parks ¦ (blank) ¦ state_parks ¦ 1
A subcategory in that subcategory named 'big' would be stored as:
100 ¦ recreation ¦ parks ¦ state_parks ¦ big ¦ 2
And a subcategory in that subcategory would be stored as:
101 ¦ recreation ¦ parks ¦ big ¦ next_subcat ¦ 3
Here is the code:
$section="recreation";
$category="parks";
$subcategory="state_parks";
$rank=1;
//delete includes
while ($subcategory) {
$rank++;
$myquery="SELECT id,subcategory FROM list WHERE section='$section' AND category='$category' AND previous_subcat='$subcategory' AND rank='$rank';" . mysql_error();
$myresult=mysql_query($myquery);
while ($myrow = mysql_fetch_assoc($myresult)) {
extract($myrow);
$id = $myrow["id"];
$subcategory = $myrow["subcategory"];
} //extracted values
echo "<BR><BR>Subcategory is $subcategory and rank is $rank<BR><BR>";
$include=$id . ".htm";
$delinclude=unlink("/home/lcdinwcy/public_html/main_includes/$include");
} //no more subcategories
$subcategory never changes so I get an infinite loop. I want it to run until no more subcategories exist and all the includes are deleted. Any suggestions? Thanks.
Try the following:
while ($myrow = mysql_fetch_array($myresult))
{echo "<BR><BR>Subcategory is $myrow['subcategory'] and rank is $rank<BR><BR>";
$include = $myrow['id'] . ".htm";
$delinclude=unlink("/home/lcdinwcy/public_html/main_includes/$include");} //no more subcategories
Think that might work. :)