I have one table for some pages. These pages are either simply pages (cat = 0) or sub-pages of a page (cat = the id of the page for it to be under)
Below works as it should,
//Get pages
$page_result = mysql_query("SELECT * FROM pages WHERE cat = '0'");
while ($page_row = mysql_fetch_array($page_result)) {
echo $page_row['title']."<br />";
//Get sub pages with id
$subpage_result = mysql_query("SELECT * FROM pages WHERE cat = '{$page_row['id']}'");
while ($subpage_row = mysql_fetch_array($subpage_result)) {
echo " - ".$subpage_row['title']."<br />";
}
}
and prints like so
Page Title //cat = 0 & id = 1
- Page Title's sub page //cat = 1
- Page Title's sub page //cat = 1
Another Page Title //cat = 0 & id = 6
- Another Page Title's sub page //cat = 6
- Another Page Title's sub page //cat = 6
- Another Page Title's sub page //cat = 6
My problem is if a root page (cat = 0) gets deleted, the subpages where cat is set to its id, will never be shown again,
I'm looking for some sort of logic to list uncatergorized subpages (where cat != 0 and the cat (pages id) doesn't exsist) in there own categorie/page like so,
Page Title //cat = 0 & id = 1
- Page Title's sub page //cat = 1
- Page Title's sub page //cat = 1
Another Page Title //cat = 0 & id = 6
- Another Page Title's sub page //cat = 6
- Another Page Title's sub page //cat = 6
- Another Page Title's sub page //cat = 6
Uncatergorized Pages //
- Some Page Title's sub page //cat = 4
- Random Page Title's sub page //cat = 7
I've had a few ideas using in_array() but I can't seem to figure it out,