Creating an array from database

Hi there,

I’ve been trying to get my head around this for hours now so I thought i’d best hit the forums.

I’m trying to create an array from my database to look like this (ticketname and cost represent data from columns in the database). And assigned to the variable $items

[php] array (
‘ticketname’ => ‘qweqwe’,
‘cost’ => ‘2,00’,
),[/php]

at the moment I have this

[php]$sql=“SELECT ticketname, cost FROM tickets”;
$result=mysql_query($sql);

while ($row = mysql_fetch_assoc($result)) {
$items[] = $row ;
}[/php]

which makes this

[php]array (
0 =>
array (
‘ticketname’ => ‘qweqwe’,
‘cost’ => ‘2,00’,
),
1 =>
array (
‘ticketname’ => ‘hjkhjk’,
‘cost’ => ‘6.00’,
),
)[/php]

any help with this would be amazing!

Thanks in advance,
Oli

This is my post, need to edit. The array needs to look like this, not as stated above:

[php] array (
‘ticketname’ => ‘cost’,
‘ticketname’ => ‘cost’,
),[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service