Okay I will show you everything but the real question is whether "db_result_to_array" can be simplified and still work with the code
the index page begins with a query to the database
$query = "select catid, catname
from categories";
$result = @($query);
simple enough
the result is then sent into a new array
$result = db_result_to_array($result);
the tricky code follows:
function db_result_to_array($result)
{
$res_array = array();
for ($count=0; $row = @mysql_fetch_array($result); $count++)
$res_array[$count] = $row;
return $res_array;
}
this outputs the following array:
ArrayArray ( [0] => Array ( [0] => 1 [catid] => 1 [1] => Internet [catname] => Internet ) [1] => Array ( [0] => 2 [catid] => 2 [1] => Self-help [catname] => Self-help ) [2] => Array ( [0]
=> 5 [catid] => 5 [1] => Fiction [catname] => Fiction ) [3] => Array ( [0] => 4 [catid] => 4 [1] => Gardening [catname] => Gardening ) )
This result is saved in "cat_array" then processed to output the array as links.
function display_categories($cat_array)
{
echo "<ul>";
foreach ($cat_array as $row)
{
$url = "show_cat.php?catid=".($row["catid"]);
$title = $row["catname"];
echo "<li>";
do_html_url($url, $title);
}
echo "</ul>";
echo "<hr>";
}
It appears that we have an array inside an array inside array. Is all of this necessary?
Can this code be simplified?
The code works I'm just wondering if there is an easier way of doing the same thing.
Thanks