473,473 Members | 2,060 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

sessions variables not changing in a for loop

I am working on a small graphing application. In the process of
graphing I use 3 seperate scripts for getting the job done. The first
is the page that the use sees and selects all the data from. This
selected data gets passed internally using session variables to the
next page. This page takes the passed data, runs it for error
checking and determines where to send it next. I have gotten most of
the desired results through this method with acceptable performance,
but I have run across a problem.

Currently my graphing script is set up to accept only an array
containing one or two variables passed in $_SESSION['dataVariables'].
If somebody where to select three variables for graphing I want them
to be able to see all three graphs on one page as the result. My
solution to this answer was to write a loop:

if(count($dataArray) > 2)
{
$count = count($data);
for($i = 0; $i < $count; $i++)
{
$_SESSION['dataArray'] = array($dataArray[$i]);
echo '<img src="graph.php" alt="graph" /><br />';
}
}

Through testing I know that the value inside of $_SESSION['dataArray']
is changing on each loop iteration, but my graphs aren't being
outputted accordingly. Each graph ends up being graphed using
whatever the last value in the array is and for the life of me I
cannot figure out where the problem is.

Any help would be greatly appreciated.

-z0ink
Jul 17 '05 #1
1 2313
z0ink wrote:
Currently my graphing script is set up to accept only an array
containing one or two variables passed in $_SESSION['dataVariables'].
If somebody where to select three variables for graphing I want them
to be able to see all three graphs on one page as the result. My
solution to this answer was to write a loop:

if(count($dataArray) > 2)
{
$count = count($data);
for($i = 0; $i < $count; $i++)
{
$_SESSION['dataArray'] = array($dataArray[$i]);
echo '<img src="graph.php" alt="graph" /><br />';
}
}

Through testing I know that the value inside of $_SESSION['dataArray']
is changing on each loop iteration, but my graphs aren't being
outputted accordingly. Each graph ends up being graphed using
whatever the last value in the array is and for the life of me I
cannot figure out where the problem is.


Ok, imagine, for the sake of argument, the user's browser is configured
to NOT display images.

It gets this HTML

<img src="graph.php" alt="graph" /><br />
<img src="graph.php" alt="graph" /><br />
<img src="graph.php" alt="graph" /><br />

and the user sees three "broken images".

Now, if the user were to select /any/ of those images and get it from
the server, /all/ would be updated to the same image.

Well ... this is exactly what happens when the browser is showing
images. It will only ask for them when it's ready and at that time your
$_SESSION data has the last value from the for loop.
So, you need a way to keep the data available for longer than the time
it takes PHP to execute the loop ... and you also need a way to tell the
browser which data to use for which image.

I'd do that by putting the graph data into arrays, like this

$_SESSION['dataArray'][$i] = array($dataArray[$i]);

so that you have the session variables
$_SESSION['dataArray'][0]
$_SESSION['dataArray'][1]
$_SESSION['dataArray'][2]
Now you just have to match each piece of data with each graph. So send a
parameter in the URL ...

<img src="graph.php?data=0" alt="graph" /><br />
<img src="graph.php?data=1" alt="graph" /><br />
<img src="graph.php?data=2" alt="graph" /><br />

and in graph.php, instead of using $_SESSION['dataArray'] use

$_SESSION['dataArray'][$_GET['data']]
HTH
Happy Coding :-)

--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: jing_li | last post by:
Hi, you all, I am a newbee for php and I need your help. One of my coworker and I are both developing a webpage for our project using php. We have a copy of the same files in different location...
4
by: Antoni | last post by:
Hello, Could anyone advise, if I had three sessions as below, is there anyway I could access the three in a loop. $_SESSION; $_SESSION; $_SESSION; Thank you
7
by: Quinonez | last post by:
here is the set up. 7 page form all get set to sessions 8th page sessions are called and results displayed for user to see this is the php script for page 8 <? ksort($_SESSION); foreach...
10
by: Mark H | last post by:
Hey all-- I'm building a database and I basically need to keep out people who aren't authorized, but it's not like I need top security here. I'm just doing basic user/pass of a SQL database, and...
9
by: Javaman59 | last post by:
Using local declarations within a block often makes code more readable, but is it less efficient? eg... void P() { while (...) { int i = ...; bool b = ...; .... } }
1
by: Pavils Jurjans | last post by:
Hello, I have a couple of unclear questions about ASP.NET sessions: First, I'd like to have some way to see how many sessions currently are running on the certain application, and, possibly, have...
1
by: Evan Nelson | last post by:
We are running our website on 3 W2K servers using classic ASP and IIS 5.0. Because the servers are load balanced we don't use the ASP Session object instead we store session type information to the...
3
by: AlonR | last post by:
Hi, We're experiencing random user sessions losses on our web applications, and are researching for any useful information which may shed light on this problem. Environment: In our...
3
by: Jon Slaughter | last post by:
Any pitfalls or stuff I need to worry about when working with sessions? I want to write a log file and hit counter along with a login interface and I'm trying to learn this stuff. ...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.