...

View Full Version : _GET is not _GETting changing values!



JaniGreen
01-14-2010, 09:38 PM
I'm working on a web page that will display relevant information about power consumption in a university. There are 4 buildings with power meters which measure power consumption every 15 minutes. The page uses POST form to switch a database query and display information for the 4 different buildings. A dynamic graph made with PHPlot is also being displayed for the different values. This is displayed as such:



for($c = 0; $c < 24; $c++)
{
$currenthour = ($c * 4);
$graphsumarray[$c] = array_partial_sum($kwresultsarray, $currenthour, 4);
}
print "<img src='sampleplot.php?arr=<?php echo serialize($graphsumarray); ?>'/>"


When the page is first accessed, the values are all initially 0 (the building selection starts on SELECT, which makes the query find nothing). However, when you select a building, the values for $graphsumarray change, but the $GET is not getting the new values. I am unserializing the data on the other end, and the graph displays, but they are all always zeros like how they started. How can I get these zeros to update to new values when the user selects a new building?

Please let me know if you require any other information to help. Thanks!!

Len Whistler
01-14-2010, 10:37 PM
if (isset($_GET['id'])){
$id = 0;
}
$id = $_GET['id'];

JaniGreen
01-14-2010, 10:44 PM
if (isset($_GET['id'])){
$id = 0;
}
$id = $_GET['id'];

The code to _GET it right now is:


$graphsumarray = unserialize($_GET["arr"]);

I tried to use use unserialize in your posted code, but it didn't work. Any ideas?

Thanks!!

Len Whistler
01-14-2010, 11:22 PM
I don't understand serialized/unserialized data and I assume the problem is that the URL doesn't like spaces or special characters. Have you checked the PHP manual on serialized/unserialized data?


There is at least one script to avoid "data loss".

http://php.net/manual/en/function.unserialize.php



----------------

JaniGreen
01-14-2010, 11:28 PM
I don't understand serialized/unserialized data and I assume the problem is that the URL doesn't like spaces or special characters. Have you checked the PHP manual on serialized/unserialized data?


There is at least one script to avoid "data loss".

http://php.net/manual/en/function.unserialize.php



----------------

I don't believe the serialization is the problem, but I will look into it. We attempted to put in the values manually they still stayed at zeros. The problem seems to stem from starting the page up with all the values equal to zero. They never change when the query changes.

hdewantara
01-18-2010, 01:13 PM
Hi,
I wonder whether it is of more something like this:

for($c = 0; $c < 24; $c++){
$currenthour = ($c * 4);
$graphsumarray[$c] = array_partial_sum($kwresultsarray, $currenthour, 4);
}
$d=serialize($graphsumarray);
$e="<img src='sampleplot.php?arr=".$d."' />";
print $e;

Regards,

MattF
01-18-2010, 01:20 PM
http://uk2.php.net/manual/en/function.urlencode.php

JaniGreen
01-19-2010, 07:39 PM
Thanks for all the advice so far. Unfortunately nothing has worked. Let me add a bit more information and see if it helps.

I added in a bit of code to turn 0s or negative numbers into the string "Unavailable" for display on a table along with the graph. If you opt to view the page source for the page which displays this table and calls for the graph after switching the building with the selection menu (which does, in fact, change the data displayed on the table), you will see that it still has "Unavailable" printed in each <td> (which is the value displayed when on the default "Select" option when the page first loads).

I'm not terribly experienced with PHP, but this disparity between what the page source says and what the page is displaying seems to be the heart of the issue. If I could make the page source updated - which I understand would likely be the effect of fixing a problem caused by something else - then I assume the correct values would actually be sent to the PHPlot image code. Does anyone know why the default values from the page first loading are not changing even when the displayed values on the page are, and how I could fix this?

JaniGreen
01-19-2010, 11:42 PM
Problem solved. The code was all working fine, but the browser (Chrome) was not handling the data correctly.

Thanks again for all the advice!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum