madmenyo Posted September 23, 2010 Share Posted September 23, 2010 Hi there. In my database table i have multiple records with multiple values that need to be fetched into an array. I think i need to do this as a multidimensional array but i'm not sure how. I can also put each record into a sepperate array but then i'm not sure how to increase the arrays name within the while loop. Hers an example: while ($recruits = mysql_fetch_assoc($recruitsquery)) { $recruit1 = array(name => $recruits['name'], health => $recruits['health'], damage => $recruits['damage'] } So how would i change $recruit1 in the next loop to $recruit2? Or how would i build a multidimensional array? Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/ Share on other sites More sharing options...
n3r0x Posted September 23, 2010 Share Posted September 23, 2010 I would do something like this $recruit = array(); $counter = 0; while ($recruits = mysql_fetch_assoc($recruitsquery)) { $recruit[$counter] = array(name => $recruits['name'], health => $recruits['health'], damage => $recruits['damage']); $counter++; } Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/#findComment-1114474 Share on other sites More sharing options...
madmenyo Posted September 23, 2010 Author Share Posted September 23, 2010 Great! Wasn't aware i could do it that way. I still like to know how to put them into a multidimensional array as that might be easier to work with the data. But I'll use your method for now. Tx a lot, Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/#findComment-1114483 Share on other sites More sharing options...
n3r0x Posted September 23, 2010 Share Posted September 23, 2010 that was a multidimensional array.. You access data through $recruit[<Number>]["name"] and so on Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/#findComment-1114491 Share on other sites More sharing options...
trq Posted September 23, 2010 Share Posted September 23, 2010 You could simply use.... $recruit1 = array(); while ($recruits = mysql_fetch_assoc($recruitsquery)) { $recruit1[] = $recruits; } and get exactly the same results as the last poster suggested. Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/#findComment-1114493 Share on other sites More sharing options...
madmenyo Posted September 23, 2010 Author Share Posted September 23, 2010 I can see clearly now the rain has gone A heap of thanks! Link to comment https://forums.phpfreaks.com/topic/214183-multidemensional-arrays/#findComment-1114505 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.