kickassamd Posted December 1, 2006 Share Posted December 1, 2006 Im having problems reading from an array via mysql_fetch_array()the function ================[code]getBoth($result){ while ($dbArray = @mysql_fetch_array($result, MYSQL_BOTH)) { $returnArray[] = $dbArray; }return $returnArray;}[/code]if i print_r(getBoth($queryResult)) i get this ============[code]Array ( [0] => Array ( [0] => Stubbs [char_name] => Stubbs ) [1] => Array ( [0] => Ic3m4n [char_name] => Ic3m4n ) [2] => Array ( [0] => Bawlz [char_name] => Bawlz ) [3] => Array ( [0] => CrispinxLongbow [char_name] => CrispinxLongbow ) [4] => Array ( [0] => Lilice [char_name] => Lilice ) )[/code]If i use [code]foreach ($online as $key => $name) { echo $name; }[/code]it just prints ==============[code]ArrayArrayArrayArrayArray[/code]So then i have to [code]foreach ($online as $key => $name) { foreach ($name as $player) { echo $player."<br>"; } }[/code]To print each name to the screen..... is there something I am doing wrong... 2 foreach loops to print an array seems wrong Quote Link to comment https://forums.phpfreaks.com/topic/29163-mysql-array-issues/ Share on other sites More sharing options...
drifter Posted December 2, 2006 Share Posted December 2, 2006 Well just looking at this arrayArray ( [0] => Array ( [0] => Stubbs [char_name] => Stubbs ) [1] => Array ( [0] => Ic3m4n [char_name] => Ic3m4n ) [2] => Array ( [0] => Bawlz [char_name] => Bawlz ) [3] => Array ( [0] => CrispinxLongbow [char_name] => CrispinxLongbow ) [4] => Array ( [0] => Lilice [char_name] => Lilice ) )your foreach $key=>$name would give you $key=0 $name=Array ( [0] => Stubbs [char_name] => Stubbs ) So you would need to do $name[0] or $name['char_name']this also means you do not need the key so you can doforeach($online AS $name){ echo $name['char_name'];} Quote Link to comment https://forums.phpfreaks.com/topic/29163-mysql-array-issues/#findComment-133813 Share on other sites More sharing options...
kickassamd Posted December 2, 2006 Author Share Posted December 2, 2006 How stupid of me.... Such a simple thing :-\ How did I overlook such a n00b mistake!Thanks so much drifter I feel so dumb now! Quote Link to comment https://forums.phpfreaks.com/topic/29163-mysql-array-issues/#findComment-133815 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.