mySQL - select problems, returning arrays
Posted: Wed Dec 18, 2002 5:49 am
Hey,
I am working on a simple forum script, and am having some trouble.
My posts have a field called 'parent', which is the post id that it belongs to. This way I can have nested posts. I want to output all of the posts (children) belonging to an other post (the parent), but for some reason my query only returns one child.
The content_get_children () function returns the array from the select query, and the content_read () takes each id in the children array and outputs it. I have five rows (posts) in the table, but it only outputs the first child post. Can you see anything wrong here?
Thanks
I am working on a simple forum script, and am having some trouble.
My posts have a field called 'parent', which is the post id that it belongs to. This way I can have nested posts. I want to output all of the posts (children) belonging to an other post (the parent), but for some reason my query only returns one child.
Code: Select all
// +-------------------------------------------+
// | content_get_children
// +-------------------------------------------+
function content_get_children ($id)
{
$result = mysql_query ("SELECT `id` FROM `sub_content` WHERE `parent` = $id");
if ($result != false)
{
$children = mysql_fetch_assoc ($result);
return $children;
}
else echo "(CONTENT GET CHILDREN)" . error (mysql_error ());
}
// +-------------------------------------------+
// | content_read
// +-------------------------------------------+
function content_read ()
{
global $content_id;
$parent_content = content_get ($content_id);
$return = format_content ($parent_content);
$children = content_get_children ($content_id);
if ($children)
foreach ($children as $child)
{
$child_content = content_get ($child);
$return .= format_content ($child_content);
} else $return = error ("No Content.");
return $return;
}Thanks