FreakyBlue Posted June 25, 2009 Share Posted June 25, 2009 Hi all, Something is driving me nuts. I can't find a solution, hopefully someone can help me. I have this array: Array ( [0] => Array ( [online_session_user] => FreakyBlue [online_session_time] => 1245835757 [online_session_ip] => 83.84.114.39 [user] => FreakyBlue ) [1] => Array ( [online_session_user] => testaccount [online_session_time] => 1245835752 [online_session_ip] => 83.84.114.39 [user] => testaccount ) ) I need this array to break down in an array like this: Array ( [online_session_user] => FreakyBlue [online_session_time] => 1245835757 [online_session_ip] => 83.84.114.39 [user] => FreakyBlue ) Array ( [online_session_user] => testaccount [online_session_time] => 1245835752 [online_session_ip] => 83.84.114.39 [user] => testaccount ) Is that possible? If not --> I can change the array into this (but than I loose the keys): Array ( [0] => FreakyBlue [1] => 1245835757 [2] => 83.84.114.39 [3] => FreakyBlue ) Array ( [4] => testaccount [5] => 1245835752 [6] => 83.84.114.39 [7] => testaccount ) Is there a possibility to recover the keys? Any help is very much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/ Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 if you save the keys.. then you get the keys simple as that.. even if you don't save em but they save automatically (auto increment) on primary value or something).. then a simple SELECT *.. will have the keys and everything. I dont know if this is even sql question in php array you can keep the keys.. like this $stats = array(1 => array("FreakyBlue", 123123123, "255.255.255.255"), 2 => array("testaccount", 123123123, "255.255.255.255")); the keys are 1,2.. etc.. Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/#findComment-863711 Share on other sites More sharing options...
FreakyBlue Posted June 25, 2009 Author Share Posted June 25, 2009 if you save the keys.. then you get the keys simple as that.. even if you don't save em but they save automatically (auto increment) on primary value or something).. then a simple SELECT *.. will have the keys and everything. Thnx for you answer. But I do not completely understand what you 're saying. The above array is covered from a Sql Select querie. I need to put this data in another database table, but that doesn't work. I guess it isn't working because of the nested thing. In array inside an array can't be put in another database table ... or am I wrong on this? Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/#findComment-863718 Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 im confused post the script Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/#findComment-863728 Share on other sites More sharing options...
FreakyBlue Posted June 26, 2009 Author Share Posted June 26, 2009 This is the original code which I've started with. It gives me the array from my first post. $sSql = ' SELECT online_session_user, online_session_time, online_session_ip, user FROM '. App::getT('online_session') .' AS s LEFT JOIN '. App::getT('user') . ' AS u ON (s.online_session_user = user) WHERE user = online_session_user GROUP BY user ORDER BY online_session_time DESC'; $lastActivity = $oDb->getRows($sSql); I can see that result (the array) by using the: die(print_r($lastActivity, true)); The question is: how do I get that array in my own database table with the columns 'online_session_user, online_session_time, online_session_ip, user'. Somehow the array in an array is stopping it. Another thing I've tried is this: $sSql = ' SELECT online_session_user, online_session_time FROM '. App::getT('online_session') .' AS s LEFT JOIN '. App::getT('user') . ' AS u ON (s.online_session_user = user) WHERE user = online_session_user GROUP BY online_session_user ORDER BY online_session_user DESC'; $sIds = ''; foreach($oDb->getRows($sSql) as $lastActivity) { $sIds .= '' . $lastActivity['online_session_user'] .', ' . $lastActivity['online_session_time'] .','; } $sIds = rtrim($sIds, ','); $a = expode(',', $sIds); This is giving me the array structure I need, but then I loose the keys. Hopefully this makes it more clear and are we able to find a solution. A thought --> I try to solve this issue through the array; breaking it down in peaces. Maybe the solution is in: --> getting the right loop through the inner arrays? --> using another sql command? Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/#findComment-863951 Share on other sites More sharing options...
fenway Posted June 27, 2009 Share Posted June 27, 2009 Lose the keys? What does that means? Besides, that doesn't sound like a mysql issue at all. Quote Link to comment https://forums.phpfreaks.com/topic/163688-nested-associative-arrays-putting-in-database/#findComment-864766 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.