PHP Fetch Array into Custom Array
Posted: Thu May 27, 2010 7:39 pm
Hi!
I was just wondering if anybody could help me figure out how to do this:
I want to select from my database "id" and "name", then I want to echo these out in a drop-down list. The way I have coded this is that I need to create an array like this:
array("1" => "Chris", 2" => "Johnston");
I'm wondering how I could go about it. I've tried mysqli_fetch_array() and only selecting the id and the name columns, but it only shows the name in my drop down without assigning the value of the id related to that name.
Also, I cannot use a counter as there are other variables involved in the WHERE clause.
I basically want to be able to do this:
array($myfetchedarray[id] => $myfetchedarray[name]);
Also, I cannot echo it out as the following:
<select value="$myfetchedarray[id]">$myfetchedarray[name]</select>
as this is an OOP script that requires an array.
Thank you in advance.
I was just wondering if anybody could help me figure out how to do this:
I want to select from my database "id" and "name", then I want to echo these out in a drop-down list. The way I have coded this is that I need to create an array like this:
array("1" => "Chris", 2" => "Johnston");
I'm wondering how I could go about it. I've tried mysqli_fetch_array() and only selecting the id and the name columns, but it only shows the name in my drop down without assigning the value of the id related to that name.
Also, I cannot use a counter as there are other variables involved in the WHERE clause.
I basically want to be able to do this:
array($myfetchedarray[id] => $myfetchedarray[name]);
Also, I cannot echo it out as the following:
<select value="$myfetchedarray[id]">$myfetchedarray[name]</select>
as this is an OOP script that requires an array.
Thank you in advance.