what I think you've missed is your array starts with []['string']
remove []...
$menu['name'] = ... should work ... unless your code is a little specific
Sincerely,
Maxim Maletsky
Founder, Chief Developer
PHPBeginner.com (Where PHP Begins)
[EMAIL PROTECTED]
www.phpbeginner.com
---
> Why do you need to put the values in an array, then read through the
> array to print the values? Why not just print each record as you get it
> from the DB?
The array is formed before the page is called. This is then passed to the
page which prints it out.
M@
> On Thu, 22 Feb 2001 02:11, M
On Thu, 22 Feb 2001 02:11, Matt Williams wrote:
> I have done it this way...
>
> $menu = array();
> $count = $db->num_rows();
> for($i = 0; $db->next_record(); $i++)
> {
> $menu[$i]["name"] = $db->f("name");
> $menu[$i]["url"] = $db->f("topic_id"
n";
}
is there any better way of doing this??
thanks
M@
> -Original Message-
> From: Pavel Kalian [mailto:[EMAIL PROTECTED]]
> Sent: 21 February 2001 15:00
> To: Matt Williams; [EMAIL PROTECTED]; PHP_UK@egroups. com
> Subject: Re: [PHP] array
> while($db->next_record())
> {
> $menu[]["name"] = $db->f("name");
> $menu[]["url"] = $db->f("topic_id");
> }
Why not use a for loop instead?
for($i = 0; $db->next_record(); $i++) {
$menu[$i]["name"] = $db->f("name");
$menu[$i]["url"] = $db->f("topic_id");
}
Then you can access them thro
> a) $menu[] = array("name" => $db->f("name"), "url" => $db->f("topic_id"));
>
> b) echo $menu[0]["name"]; //for example - depends on what you want to do
Thanks, maybe I should have made myself a little clearer though
I am expecting more than one row to be returned from the db.
So how would I
a) $menu[] = array("name" => $db->f("name"), "url" => $db->f("topic_id"));
b) echo $menu[0]["name"]; //for example - depends on what you want to do
BTW have a look into the manual, the array stuff is described pretty well
Pavel
- Original Message -
From: "Matt Williams" <[EMAIL PROTECT
7 matches
Mail list logo