Jump to content

Recommended Posts

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!

 

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..

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?

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?

 

 

 

 

 

 

 

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.