[SOLVED]while-loop, do until false
Posted: Mon Jul 26, 2004 7:19 am
I've got this code for checking if the current page showing has any parent-pages available:
what i'm trying to do is to check if the current page has any parents, and if it gets a match (pid is the current pages parent page-id), it adds the name of the parent page into $output['parents'], and tries to find a parent of the parent-page. The problem is that the code i'm using above just results in an timeout. Doesn't this type of thing work? Does anyone have any idea on how to fix it?
Thanks in advance.
Code: Select all
<?php
###### get the pages parent(s)
$more['parents'] = true;
$more['pid'] = $output['pid'];
// while there's still more parents
while ($more['parents'] == true) {
$query['parents'] = @mysql_query ("SELECT `pid`,`name` FROM `contents` WHERE `id` = '{$more['pid']}'");
$cparent = @mysql_fetch_assoc ($query['parents']); // fetch content
$more['parents'] = false;
if (!empty ($cparent['name'])) {
$output['parents'] .= "» {$cparent['name']} ";
if (!empty ($cparent['pid'])) $more['parents'] = true;
}
}
##### /get the pages parent(s)
?>Thanks in advance.