Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    _GET is not _GETting changing values!

    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:

    PHP Code:
    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!!

  • #2
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    PHP Code:
    if (isset($_GET['id'])){
    $id 0;
    }
    $id $_GET['id']; 
    Leonard Whistler

  • #3
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Len Whistler View Post
    PHP Code:
    if (isset($_GET['id'])){
    $id 0;
    }
    $id $_GET['id']; 
    The code to _GET it right now is:

    PHP Code:
    $graphsumarray unserialize($_GET["arr"]); 
    I tried to use use unserialize in your posted code, but it didn't work. Any ideas?

    Thanks!!

  • #4
    Senior Coder Len Whistler's Avatar
    Join Date
    Jul 2002
    Location
    Vancouver, BC Canada
    Posts
    1,323
    Thanks
    26
    Thanked 100 Times in 100 Posts
    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



    ----------------
    Last edited by Len Whistler; 01-14-2010 at 10:26 PM.
    Leonard Whistler

  • #5
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Len Whistler View Post
    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.

  • #6
    Regular Coder hdewantara's Avatar
    Join Date
    Aug 2009
    Location
    Jakarta, Indonesia.
    Posts
    349
    Thanks
    9
    Thanked 51 Times in 50 Posts
    Hi,
    I wonder whether it is of more something like this:
    PHP Code:
    for($c 0$c 24$c++){
      
    $currenthour = ($c 4);
      
    $graphsumarray[$c] = array_partial_sum($kwresultsarray$currenthour4);
    }
    $d=serialize($graphsumarray);
    $e="<img src='sampleplot.php?arr=".$d."' />";
    print 
    $e
    Regards,
    Last edited by hdewantara; 01-18-2010 at 12:14 PM. Reason: missing quote

  • #7
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts

  • #8
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #9
    New to the CF scene
    Join Date
    Jan 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Problem solved. The code was all working fine, but the browser (Chrome) was not handling the data correctly.

    Thanks again for all the advice!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •