format Posted March 13, 2014 Share Posted March 13, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/ Share on other sites More sharing options...
requinix Posted March 13, 2014 Share Posted March 13, 2014 Store that information in a database instead. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472480 Share on other sites More sharing options...
format Posted March 13, 2014 Author Share Posted March 13, 2014 The information is created in real time as a user ansers questions about their personality. They do not login so seesions are used to tra\ck results. Sessions get updated as each question is answered. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472482 Share on other sites More sharing options...
requinix Posted March 13, 2014 Share Posted March 13, 2014 And? The fact that people don't log in is irrelevant. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472495 Share on other sites More sharing options...
Zane Posted March 13, 2014 Share Posted March 13, 2014 Without any code, I would suggest that you order all your arrays descending and grab the first element in each array. Boom, max values collected! Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472499 Share on other sites More sharing options...
format Posted March 13, 2014 Author Share Posted March 13, 2014 Ok, your not going to answer the origanal question. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472500 Share on other sites More sharing options...
requinix Posted March 13, 2014 Share Posted March 13, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472503 Share on other sites More sharing options...
format Posted March 13, 2014 Author Share Posted March 13, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472506 Share on other sites More sharing options...
requinix Posted March 13, 2014 Share Posted March 13, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472509 Share on other sites More sharing options...
Zane Posted March 13, 2014 Share Posted March 13, 2014 (edited) 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 March 13, 2014 by Zane Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472514 Share on other sites More sharing options...
format Posted March 14, 2014 Author Share Posted March 14, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472558 Share on other sites More sharing options...
format Posted March 14, 2014 Author Share Posted March 14, 2014 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 Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472562 Share on other sites More sharing options...
requinix Posted March 14, 2014 Share Posted March 14, 2014 (edited) 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 March 14, 2014 by requinix Quote Link to comment https://forums.phpfreaks.com/topic/286944-max-value-from-separate-arrays/#findComment-1472611 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.