Jump to content

MAX Value From Separate Arrays


format

Recommended Posts

Hi All, is it poossible to loop through separate PHP SESSIONS to find the MAX Value, ending up with the Name of the SSEEION and its Value

 

Example, I have 3 PHP Seesions:

 

1. Joe has the value 1

2. Bill has the value 2

3.Jane has the value 3

 

I would like to get the name of the SESSION with the MAX value.

 

In this case its Jane.

 

Many thanks for help

 

Jon

Link to comment
Share on other sites

Ok, your not going to answer the origanal question.  Thanks.

Your problem was that you didn't know how to get the data from the other sessions. My solution is to not use sessions because if you put it all in a database then you can get the other data.

But hey, solved or not solved makes no difference to me.

Link to comment
Share on other sites

I have seven tables storing alter ego character traits.  These are looked up as a person answers 7 questions one at a time.  I used sessions to hold and increase the weight of each character as the questions where answered.  I just wanted to know if it was possible to sort through individual seesions.  Your answers may be the right way, I dont question this, they just dont help me awnser the first question. 

Link to comment
Share on other sites

Uh... Just to be absolutely clear here: when you say you have three "sessions", are you saying that you have three visitors to your site and you want to be able to access all three's session data at the same time? Or that you have three things of data in the session and you want a maximum value of them?

 

Or perhaps simpler, what's your code so far?

Link to comment
Share on other sites

Yes, I was also pretty off-put by that wording.

 

Unless you're traversing through the session files stored in your servers tmp directory, I only know of one $_SESSION to loop through, and that is the current one. I imagine about the same thing as requinix...

$_SESSION['sessionOne'] = range (5,5000);
$_SESSION['sessionTwo'] = range (5,6000);
$_SESSION['sessionThree'] = range (5,7000); 
Provide code if you're asking questions about it.

 

I have seven tables storing alter ego character traits.

Seven tables full of nothing but traits? Like attributes? Key/Value pairs?

I sense a non-normalized db structure, but that's a whole different can of worms.

Edited by Zane
Link to comment
Share on other sites

Apologies if un-clear.  I used the number three to simplify things.

 

As a visitor to the site answers multiple quetions about their personal characteristics, 20 different Sessions are created.  Each one represnts an "Alter Ego".

 

As each question gets answered the sessions get updated to reflect the persons answers.  Each seeion starts off with a zero score and goes up each time by 1 or 3 based on the answers.  At the end I would like to get the name and value of the Session with the highest number.

 

I am hoping to put these sessions into an array and eirher sort them or find MAX to locate the right one.  Is this possible?

 

Thank you for your time.

Link to comment
Share on other sites

Update,  I have it working if not perfectly.

 

<?php
   $value = max($qresults);
   $key = array_search($value, $qresults);
   echo $key;
?>   

 

 

The above works great, it will return the first max it finds if two have the same value.

 

If a better option exists I would be interested in knowing.  Many thanks

Link to comment
Share on other sites

Actually, that's the way I would do it too.

 

[edit] For the record, a "session" tends to mean a user's $_SESSION and the underlying technology to support it. "Two sessions" is a bit weird but could mean either two users and their two separate sets of $_SESSION values, which is what I thought at first, or one user somehow with two sessions (like maybe you destroyed the first session and started a second one). "Three sessions" is even weirder.

Edited by requinix
Link to comment
Share on other sites

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.