Page 1 of 1
Array question
Posted: Thu Mar 23, 2006 4:42 pm
by ms_tilly
hiya,
in this array
Code: Select all
while($row = mysql_fetch_assoc($result)) {
$data[] = $row;
}
print_r($data);
why do i get this
Code: Select all
Array ( [0] => Array ( [u_id] => 14 [name] => Smith ) )
and not
Code: Select all
Array ( [u_id] => 14 [name] => Smith )
thanks for your help
Posted: Thu Mar 23, 2006 4:54 pm
by feyd
$row is an array. You're adding an entry to another array ($data.)
Re: Array question
Posted: Thu Mar 23, 2006 4:55 pm
by Benjamin
Code: Select all
$Counter = 0;
while($data[$Counter] = mysql_fetch_assoc($result)) { $Counter++; }
print_r($data[0]); // prints the first row array
print_r($data); // prints all row arrays
Posted: Thu Mar 23, 2006 5:06 pm
by ms_tilly
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
so i could get around by getting rid of the while
Code: Select all
$row = mysql_fetch_assoc($result);
print_r($row);
and then i can reference that like...
is that right?
feyd | Please use Code: Select all
tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Thu Mar 23, 2006 5:10 pm
by feyd
basically, yes.
Posted: Thu Mar 23, 2006 5:10 pm
by Benjamin
Code: Select all
$Data = mysql_fetch_assoc($link);
$username = $Data['name']);