mrhobbz Posted October 29, 2008 Share Posted October 29, 2008 I need some help with an array setup, I'm not 100% sure how to do this. To start off, I have a mysql table that has a name and a few other attributes. There will be multiple of the name and different, varrying attributes. Here is the array.. while ($row = mysql_fetch_row($result)){ foreach($row as $key=>$value) { $raid = $row[1]; $boss = $row[2]; $comp = $row[3]; $status = array ( array($raid, $boss, $comp) ); } Basically instead of it creating a seperate array for each row in the table, I want it to merge the array based on the "raid" column. Is there an easy way I can do this or would I be better off using two different databases, one for the "raid" lists and the second for the bosses, querying the "bosses" database and pulling it based on the raid name column? Quote Link to comment https://forums.phpfreaks.com/topic/130603-array-help/ Share on other sites More sharing options...
Mchl Posted October 29, 2008 Share Posted October 29, 2008 Like this? while ($row = mysql_fetch_row($result)){ $status[] = array( "raid" => $row[1], "boss" => $row[2], "comp" => $row[3], ) } Or maybe: while ($row = mysql_fetch_row($result)){ $status[$row[1]] = array( "boss" => $row[2], "comp" => $row[3], ) } Quote Link to comment https://forums.phpfreaks.com/topic/130603-array-help/#findComment-677566 Share on other sites More sharing options...
mrhobbz Posted October 29, 2008 Author Share Posted October 29, 2008 Ehh sort of I was more or less looking to stick them all in a single array say i have four rows in my table all with "pizza" as the common raid column and another four rows with "bagel" as the rad column. I'm trying to stick them into an array such as... pizza ->boss->blah ->boss->blah ->boss->blah ->boss->blah bagel ->boss->blah ->boss->blah ->boss->blah ->boss->blah I'm thinking it may be easier to just use two databases. Quote Link to comment https://forums.phpfreaks.com/topic/130603-array-help/#findComment-677570 Share on other sites More sharing options...
sasa Posted October 29, 2008 Share Posted October 29, 2008 try while ($row = mysql_fetch_row($result)){ $status[$row[1]][] = array( "boss" => $row[2], "comp" => $row[3], ) } Quote Link to comment https://forums.phpfreaks.com/topic/130603-array-help/#findComment-677685 Share on other sites More sharing options...
mrhobbz Posted October 29, 2008 Author Share Posted October 29, 2008 Good eye, thats what I was looking for. Thanks everyone! Quote Link to comment https://forums.phpfreaks.com/topic/130603-array-help/#findComment-677732 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.