473,406 Members | 2,633 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Set array as session

TheServant
1,168 Expert 1GB
I am trying to get data from a MySQL table and then store it in the session. I used to define each variable like:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['var1'] = $table['var1'];
  2. $_SESSION['var2'] = $table['var2'];
But after re-doing my code, there has to be an easier way. First I simply tried:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION = $table
Then
Expand|Select|Wrap|Line Numbers
  1. foreach( $user_data as $key => $value ) {
  2.         $_SESSION[$key] = $value;
  3.     }
Probably really stupid mistake I'm making, but can someone help me out?
Mar 18 '09 #1
9 2916
Dormilich
8,658 Expert Mod 8TB
what about
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['db_data'] = $table;
?
Mar 18 '09 #2
TheServant
1,168 Expert 1GB
But then the array will be stored as a variable and I will have to call it via:
Expand|Select|Wrap|Line Numbers
  1. $_SESSION['db_data']['var1']
Won't I? I will try it when I get home, but there's got to be a logical way to transfer keys and values to another array.
Mar 18 '09 #3
Dormilich
8,658 Expert Mod 8TB
sure, but what's the problem with it?
Mar 19 '09 #4
TheServant
1,168 Expert 1GB
lol, I'm lazy and looking for less coding. I think what I'm going to do anyway is simply have one variable in my session and the rest I will call from MySQL as needed per page. This means two MySQL queries per page, but for the sake of 10 variables it might be quicker than a 100 variable array plus one MySQL query? Not sure...
Mar 19 '09 #5
Dormilich
8,658 Expert Mod 8TB
probably. and if you use prepared statements, it could be even quicker to query the DB twice (despite the memory advantage), but that's only a guess.
Mar 19 '09 #6
TheServant
1,168 Expert 1GB
What do you mean prepared statements?
Mar 19 '09 #7
Markus
6,050 Expert 4TB
So, parametrized statements abstract the data out of the statement, and I assume it is then cleansed through the binding?

I have used this method before (still do, in fact) but I wasn't aware of it's name or it's benefits.

- Mark.
Mar 20 '09 #9
TheServant
1,168 Expert 1GB
Interesting. Thanks for the info.
Mar 22 '09 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: Bart Plessers \(artabel\) | last post by:
Hello, My script builds a list of files in a folder. These files are stored in an 2-dimensional array, called "a_files". To speed up the script, I don't want the filelist everytime being read...
3
by: NCZIMM | last post by:
I am trying to create a session array then use the array in a foreach. I get an error saying: "foreach statement cannot operate on variables of type 'object' because 'object' does not contain a...
4
by: Michael Kirchner | last post by:
Hi everybody The output of my multiple dimension array is quite confusing. Im declaring an array, store some values in it and then I save the array in a session variable. On an other page I...
0
by: JLSSCH | last post by:
I am having trouble retrieving the value of a Session variable that ha a string array (the same problem occurs if I use a numeric array stored in it when I redirect from one page to another. The...
3
by: Brad | last post by:
I am storing an array which contains about a dozen chracter items to a Session variable. Later, I need to use this array so I am doing the following: Dim eventTypes As String() =...
5
by: Diffident | last post by:
Hello All, I have a 2-dimensional array that I am storing as a session variable. I have no idea on how I can cast the session variable back to 2-dimensional array. Any pointers? Reference...
4
by: MrBiggles | last post by:
Here's the sitch: I read in a csv file with 60000 lines (20 fields per record), and store the data to a local array. The file is read in and stored just fine and pretty quick. Now, if I try to...
4
by: _Mario.lat | last post by:
Hallo, I have a little question: In the function session_set_save_handler I can pass the name of function which deal with session. In Xoops code I see the use of this function like that: ...
5
by: juan | last post by:
Hello, I have a web project in Visual Basic 2005. I want to create a session variable in the "global.asax" file as an array of strings type. The syntax I use is the following: ...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.