Page 1 of 1

Can I do Array("2" => "Value", "

Posted: Wed Oct 19, 2005 8:11 am
by svdelle
feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Is it possible to create an array like this based on auto_increment value and a set text value by iterating through a list of records?

Code: Select all

$list = array(
	"2" => "ItemOne",
	"5" => "ItemTwo",
	"21" => "ItemThree",
	"32" => "ItemFour",
	"43" => "ItemFive",
);
How I think (it's an outline, and I know this wont work):

Code: Select all

$categories = array();
$counter = 0;
while($row = $connector->fetchArray($result)){
	$categories[$counter] = $row['ID'] . ' => ' . $row['Item'];
	$counter++;
}

Where "2" is the auto_increment value for the record and "ItemOne" is the corresponding value.

What I'd like is to generate a list of menu items based on its auto_increment ID in the database and the set menu item value (text).

Any hints, anyone?


feyd | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Posted: Wed Oct 19, 2005 8:33 am
by feyd

Code: Select all

$categories[$row['ID']] = $row['Item'];

Posted: Wed Oct 19, 2005 9:45 am
by svdelle
Oh my god, why didn't I think of that ... so clean and simple!

Thank you very much, that saved my day!

And I'll read up on the using php code-issue as well, thanks for pointing that out as well.