I am trying to get data from a MySQL table and then store it in the session. I used to define each variable like: - $_SESSION['var1'] = $table['var1'];
-
$_SESSION['var2'] = $table['var2'];
But after re-doing my code, there has to be an easier way. First I simply tried:
Then - foreach( $user_data as $key => $value ) {
-
$_SESSION[$key] = $value;
-
}
Probably really stupid mistake I'm making, but can someone help me out?
9 2916
what about - $_SESSION['db_data'] = $table;
?
But then the array will be stored as a variable and I will have to call it via: - $_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.
sure, but what's the problem with it?
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...
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.
What do you mean prepared statements?
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.
Interesting. Thanks for the info.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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() =...
|
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...
|
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...
|
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:
...
|
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:
...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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...
|
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,...
|
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...
|
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...
|
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,...
|
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...
| |