How do I create this array? (PHP)

Posted by jpjp on Stack Overflow See other posts from Stack Overflow or by jpjp
Published on 2010-05-24T21:16:21Z Indexed on 2010/05/24 21:21 UTC
Read the original article Hit count: 127

Filed under:
|

I am a little stuck on how to create this array.

My data:

category_id | category_name
     1              bikes
     2              cars
     3              books
     4              computers

Array:

$category=array();
$query = "SELECT * FROM categories ORDER BY name ASC";
$result = $db->query($query);
$category=array('category_id'=>$category_id, 'category_name'=>$category_name);
while ($row = $result->fetch_array()){
    $category_id=$row['category_id'];
    $category_name=$row['name'];
}

I want to create an array so that I can echo the data in a radio list like...

<input type='radio' value='<?PHP echo $category['category_id']; ?>' 
name='category[]'><?PHP echo $category['category_name']; ?>

o bikes
o cars
o books
o computers 

The problem is that the array only consists of one pair (1, bikes) and not all the data. How can I make an array with all the data?

Thanks!

© Stack Overflow or respective owner

Related posts about php

Related posts about arrays