I need to know exaclty everything to truly understand. Otherwise I feel that I am operating blindly
This two "dimensional array that contains array" is understood but could you be more detailed: what is the main array, what is each other array within this array.
please explain $row=my_sql_fetch_array($result).
I understand that "my_sql_fetch_array" creates a numeric and associative array. BUt what exactly does $row now equal.
Also I am not clear on $res_array[$count]=$row.
What does this do.
Thanks again
First, try keeping the reply in the same thread by clicking post reply, not the new thread button.
now about the 2D array.
based on the code you posted,
$query = "select catid, catname from categories";
result=mysql_query($query);
...
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;
}
each array place in $res_array is being set to contain the associative array $row
mysql_fetch_array($result) returns an associative array of the result.
let's say that your DB row contains 3 fields (id,name,email)
let's also say that the first result is id=1,name='john doe',email='jdoe@nowhere.com'
res_array[0] will look like this:
res_array[0] = (id=1,name='john doe',email='jdoe@nowhere.com')
it can be referenced by res_array[0]['id'] which outputs 1
...
$cat_array=$res_array
for each ($cat_array as $row)
{
$url="show_cat.php?catid=".($row["catid"]);
$title = $row["catname"];
echo "<li>;
do_html_url($url, $title);
}
in $title = $row["catname"] title is being given the value of 'catname' from the current row in the query result
so if catname = 'php news' then title now = php news.
does this help at all?