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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post

    clearing the memory after a trip to the server?

    ok, i'm sure you all will laugh at this, but it seems really bizzario to me.

    i have two small routines worked out.
    routine G gets a value out of the db and brings it back to the browser script.
    routine P puts a value into the db from the browser script.
    they both run fine.

    but.........
    you have to turn the browser totally off and restart it after retrieving a value out of the db (?) why? is this some kind of "clear memory" i need to be doing. its like the last value i retrieved thru the server is stuck in memory and keeps coming up, and it won't flush out until i turn the browser off and restart it.

    is this a Javascript problem or a PHP problem?

    i dont' have a clue, maybe i need to somehow flush the memory in the PHP file after i echo() back the result.? is that normal?

    thanks,
    Paul

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Are these "two small routines" done via AJAX???

    If so, then of course you would have to use the AJAX response to change/clear the value.

    If they aren't AJAX, then I would suspect that the problem is just that your browser is caching the first result. You just need to break the cache. There are many ways of doing that, though I'm surprised it is necessary with a PHP page.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Paul Williams (01-22-2012)

  • #3
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    Old Pendant,
    thank you for your post. i appreciate it very much.
    that does shine some light on the issue.
    some sort of cache memory problem either on the server-script side or on the client-script side.

    here is where i'm coming from...........

    my textbook: javascript, the missing manual
    ch.11 introducing Ajax
    pg.418 dives into the get() and post() calls to the server.
    this is all under "ajax the jquery way".

    knowing that, here is my call to the server, from javascript (client-script), to run the routine to
    "go get the value out of the db that i need, and then assign it to the variable statusIndex"
    i assume that the call -- $.get()
    is "Ajax using a Jquery statement"

    Code:
    $.get('getStatus-server-script.php', processResponse);
    
    function processResponse(data,status){
        if (status == 'success')  {  statusIndex = data     } 
        else                      {  statusIndex = 'error'  }
    }
    here is the server-script being called, 'getStatus-server-script.php', which plucks the value out of the db. it is all PHP code and works fine.

    Code:
    <?php require_once('Connections/connFtH.php'); ?>
    
    <?php
    mysql_select_db($database_connFtH, $connFtH);
    $result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
    $row_result = mysql_fetch_assoc($result);
    $index = $row_result['status_index'];
    			
    echo "$index";
    ?>
    thats the whole "G" routine to "Get" or "pluck" a value out of the db and return it to the client-script.

    now herein lies the problem.
    when the value comes back to the client-script, it comes back correctly on the first run. lets say the value passed back on the first run was 2.

    then i run other routines to put new values into the same column in the db.

    then at some point later (without shutting down the browser and restarting), i re-run the same "pluck" routine, and the original value of 2 keeps showing up.

    so i'm not sure if this 'memory' issue is being caused by the PHP code or by the Javascript/Jquery/Ajax code.

    how would you clear the cache memory on the server-side?
    and/or how would you clear the cache memory on the client-side?

  • #4
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    i found an old post on this site, 2007, that delt with a similar problem.
    their fix was to use $.post() instead of $.get() ajax/jquery.
    they claimed that the $.get() cmd uses the cache memory (for some reason, i don't know and they didn't say).
    and that by using the $.post() cmd, you avoid the cache memory problem.

    so i changed $.get() call:

    Code:
    $.get('getStatus-server-script.php', processResponse);
    to a $.post() cmd like this:

    Code:
    $.post('getStatus-server-script.php', processResponse);
    and "sure enough" the memory problem went away.

    HOWEVER, while running several numbers in and out of the MySQL database, something else came up.
    i have the column in the db that stores this value declared as in INTEGER, yet every time i store a "0" (the number 0), it wont show up when i call it.
    why?
    hello........ZERRO is an integer !!
    is there some problem with storing 0 in the db?

    yikes, this is sure frustrating.

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Why not DEBUG DEBUG DEBUG???

    Just for starters, there's no reason you *MUST* use AJAX to hit that PHP page.

    So simply use your browser and type in the URL getStatus-server-script.php (with appropriate domain name prefix, if needed).

    That will return a value to your browser screen.

    Is it the number you expect???

    I do see one small error, which probably doesn't matter.

    You say that the index value is always an integer.

    If that is so, then WHY are you making it into a string? You are doing
    Code:
    echo "$index";
    If you want an integer, you should just do
    Code:
    echo $index;
    Again, that probably doesn't matter. Because when you grab that value in the JavaScript code via
    Code:
    statusIndex = data;
    unless you then add something to statusIndex JavaScript probably won't care if it's a string or a number.

    Still, I believe in using the proper data types where possible, so I'd omit the quotes.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Paul Williams (01-23-2012)

  • #6
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    And then the other obvious debug point is here:
    Code:
    function processResponse(data,status){
        alert( "status is ::" + status + "::\ndata is ::" + data + "::\n");
        if (status == 'success')  {  statusIndex = data     } 
        else                      {  statusIndex = 'error'  }
    }
    Or you could use a debugger (e.g., Firebug) and put a breakpoint there and examine the values being returned. But to me there's nothing wrong with scattering a few alert()s for debug purposes.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Paul Williams (01-23-2012)

  • #7
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    Old Pendant,
    thank you again for your response.

    i am doing lots of DEBUGING, that's why i'm here, can't figure out whats wrong.
    on my side of the isle, there are alert() stmt's between every line of code, spitting out the values of all these variables coming and going, so i can track where the code is failing.
    just way too messy to leave that in the code on this post; and it becomes hard to see the real code doing the heavy lifting if i leave all those alert() stmts in when asking for help.


    changing
    Code:
    echo "$index";
    to
    Code:
    echo $index;
    always helps. your right in that the values will default by type.
    however one needs to stay with proper data types between calls.
    i admit, i missed that.

    however, the issue of the "put" routine having trouble putting the value of 0 (zero) into the MySQL database is still very puzzling.
    this should not be a problem at all, especially since all other integer values (1...9...999) store into the db correctly.
    the routine should store 0 into the db as easily as any other integer.
    integer values are ...-3, -2, -1, 0, 1, 2, 3,...

    or could that be the problem?
    the value of that column in the db is declared as:
    Code:
    type = int(11) 
    Null = no
    Default = none
    maybe i'm not declaring that value in the db correctly.
    still pretty new at MySQL.
    ideas?

    thanks,
    Paul Williams

    ps. thought i was watchin good old fashion Dick Butkus style football Sunday afternoon during the 49rs/Giants game. wow, that was great.
    a pic of Eli Manning after the game said it all; covered with mud and dirt, torn uniform, bloody, grass stains, scars on his helmet, man he looked great!!

  • #8
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    INT is proper data type. Even if you used INT UNSIGNED, zero would still be legal.

    I guess I thought you *were* successfully storing a zero in the table; I thought you were just having trouble retrieving a zero.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Paul Williams (01-23-2012)

  • #9
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    no, that's just the problem.
    when i go to store 0 in the db, then the db won't have it.

    i tried changing the value in the db to TINYINT (0...255)
    and back again to INT (0...4294967295)
    and nothing changed.
    i tried UNSIGNED and even UNSIGNED ZEROFILL
    still no change.

    they both should work just fine, we all know in each case 0 is a valid integer.

    i'm starting to think that something in my mysql.db is corrupt or in my apache.server.php is corrupt.

    here is an example of what is going on:
    now this is really happening on my system (no kidding):
    from the begining:
    store 0 in db, go to db and refresh then look? 0 is there, ok.
    store 1 in db, go to db and refresh then look? 1 is there, ok.
    store 2 in db, go to db and refresh then look? 2 is there, ok.
    store 3 in db, go to db and refresh then look? 3 is there, ok.
    store 0 in db, go to db and refresh then look? 0 is NOT there as a new entry, WHAT? i just ran a routine that stored 0 in the db, why is it not there?
    store 1 in db, go to db and refresh then look? NOPE, 1 is NOT there as a new entry, why?
    store 2 in db, go to db and refresh then look? NOPE, 2 is NOT there as a new entry, why?
    store 533 in db, go to db and refresh then look? 533 is there as a new entry, ok.

    look, i don't care if i store 0 ten times in a row, i want ten rows that each have a new primary-key, a new value of 0, and a new TIMEDATE stamp for each of the ten entries, even if it is the same number ten times. the db should record each entry irregardless of the last or any previous entries.

    even if i stored 1 then 0 then 1 then 0 then 1 then 0 then 1 then 0,.....
    the db should have matching entries, EVERYTIME.

    even using the $.get() and $.post() cmd's are kinda screwy in different situations. that's not right. each of those cmd's, like all cmd's, have a syntax to them, and if you set them up right, they will work. that's what they were made to do. but..........they don't always work on my system.

    argh!!!!!!!!
    coding is not that hard, its quite easy.

    look, i'm not trying to beat anyone up here, its just that something is not working like it should, or there is some inherant behavior of some command that is kicking in, that i'm not aware of. like the $.get() command using the cache memory and screwing you up. well, that inherant behaviour is NOT talked about in the text books for these commands. bah humbug !! if a command is like that, then the definition of that command should at the very least mention it!!

    i give up, i'll just go chop wood. maybe i can get that right.
    hold ax handle here.
    impact wood there.
    wood splits.
    PRETTY SIMPLE !!

    i got an even better idea,
    i know i can get this one right
    "...hey honey, come here................."
    (don't ask )

  • #10
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Well, it would help a lot if you'd show the code you are using to store those values that aren't working.

    And it would also help a lot if you would run that code from a query tool, not from PHP.

    I'm assuming that your query is failing, but you aren't trapping the failure in the PHP code.

    But that's purely a guess and I can't say for sure until I see the query *AND* the structure of your table.

    From a query tool, do thie:
    Code:
         DESCRIBE cpqc_status;
    (assuming that's the table with the problem...if not, use the problem table name) and copy/paste the results here.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #11
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    Old Pendant,
    thank you for your response.

    here is the table in the MySQL db

    Code:
    DESCRIBE cpqc_status
    
    Field        :: Type             :: Null :: Key :: Default           :: Extra 
    row_id       :: int(10) unsigned :: NO   :: PRI :: NULL              :: auto_increment
    status_index :: int(3) unsigned  :: NO          :: NULL
    updated      :: timestamp        :: NO          :: CURRENT_TIMESTAMP :: on update  CURRENT_TIMESTAMP
    
    Show 30row(s) 
    starting from row # 0
    in horizontalhorizontal (rotated headers)vertical mode and repeat headers after 100 cells
    the code comes in two seprate sections:

    1) get current status from db
    a) jquery/ajax call to server to get current status from db
    b) php action on db and echo back status

    2) put a new status in db
    a) jquery/ajax call to server to put new status into db
    b) php action on db and echo back status

    i'll list each section of code (without all the alert()'s),
    and a note at the bottom of each section on the issues





    1) get current status from db
    a) jquery/ajax call to server to get current status from db

    Code:
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function(){
        $('#mainContent a').click( function() {  
            
            $.post('getRangeStatus-server-script.php', 'dataOut=0', processResponse);							  
            function processResponse(data,status){
                if (status == 'success')  {  statusIndex = data     } 
                else 	              {  statusIndex = 'error'  }
    				
                if (statusIndex == 0) {alert('line 74:  statusIndex = ZERO ='+statusIndex)}		
                else                  {alert('line 75:  statusIndex = ? ='+statusIndex)  }
            };  //end processResponse function
    				
            return false;  // stop the link from reloading the page or traveling elsewhere
    		
        });  // end mainContent.click function
    }); // end document.ready function
    </script>
    note: reassigning the call to the server as $.post() seemed to cleaned up the cache memory problem.
    the if/else alert() lets me know the value that is coming back....0 or greater than 0.
    not sure why i need to send out 'data=0' ? but earlier, it wouldn't work if i didn't. so i left it in there, but that seems lousy coding practice, i don't like that. and the doctrine for this cmd sez its optional (?).
    yet, it works fine, it always brings back whatever is currently in the db for status_index.





    1) get current status from db
    b) php action on db and echo back status

    Code:
    <?php require_once('Connections/connFtH.php'); ?>
    <?php
        mysql_select_db($database_connFtH, $connFtH);
        $result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC");
        $row_result = mysql_fetch_assoc($result);
        $index = $row_result['status_index'];
        
        echo $index;
    ?>
    note: again, this routine seems to work fine, it always brings back whatever is currently in the db for status_index.





    2) put a new status in db
    a) jquery/ajax call to server to put new status into db
    Code:
    <script type="text/javascript" src="js/jquery.js"></script>
    <script type="text/javascript">
    
    $(document).ready(function(){
        $('#mainContent a').click( function () {	
            
            $.get('putRangeStatus-server-script.php', 'dataOut=1', processResponse);						
            function processResponse(dataIn,status){
                if (status == 'success')  {  putData = dataIn   }    
                else 		      {  putData = 'error'  }
    
                alert('line 70; value of putData ='+putData)  // show me the value of 'data' passed back        
            };  //end processResponse function
    	
            return false;  // stop the link from reloading the page or traveling elsewhere
    
         });  // end mainContent.click function
    }); // end document.ready function
    
    </script>
    note: here is where the trouble starts, i can start by pushing 1 or 0 into the db via 'dataOut=1' or 'dataOut=0',
    and i'll get an echo() back of the correct value, supposedly put into the db.....and we go on....as i said in the last post....
    note2: i tried to use $.post on the call and $_POST on the server-script but couldn't get that to match up (?), have no idea why. so i just left it as $.get/$_GET, maybe that's part of the trouble, i don't know. syntax seems to be correct according to my references.
    note3: when it works, it works fine, until..............as last post..



    2) put a new status in db
    b) php action on db and echo back status
    Code:
    <?php require_once('Connections/connFtH.php'); ?>
    
    <?php 	
    $data = $_GET['dataOut'];
    mysql_select_db($database_connFtH, $connFtH);
    mysql_query("INSERT INTO cpqc_status (status_index) VALUES ('$data')");
    
    echo $data;
    ?>
    note: when it works, it seems to work fine, until..............last post..



    hopefully that will help.
    thats all the code on this one.
    i do appreciate your help, very very much.
    thank you,
    Paul Williams

  • #12
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Okay...let's do this:

    Create a test PHP page with this code:
    Code:
    <?php require_once('Connections/connFtH.php'); ?>
    
    <?php 	
    $data = $_GET['dataOut'];
    mysql_select_db($database_connFtH, $connFtH);
    $sql = "INSERT INTO cpqc_status (status_index) VALUES ($data)";
    echo "DEBUG SQL: " + $sql + "<hr/>";
    
    mysql_query( $sql ) or die( mysql_error() );
    
    echo $data;
    ?>
    Name that anything you want: test.php is fine.

    Then invoke it from the browser via the URL
    Code:
    http://hostname/path/test.php?dataOut=0
    And tell us
    (1) What does the DEBUG show you is being used for the query?
    (2) Did you get an error message?
    (3) After you do that, assuming you didn't get an error message, does that new record appear in the table?

    For (3) you could use phpmyadmin and a query such as
    Code:
    SELECT * FROM cpqc_status ORDER BY row_id DESC LIMIT 3
    ************

    Notice that I omitted the '...' around $data in your SQL query. Again, the field is an integer, the value is an integer. So don't treat it as a string. MySQL lets you get away with such sloppiness (some DBs don't), but why do it?
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    Paul Williams (01-24-2012)

  • #13
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post

    Old Pedant (oops, sorry, i miss spelled that earlier)(my apologize),
    thank you for post and patience.
    hopefully others are watching and will learn, or this will become valueable to someone later.

    ok, so i setup a new test page and invoked it from a browser in the url, passing the argument as a query on the end.

    Code:
    And tell us
    (1) What does the DEBUG show you is being used for the query?
    (2) Did you get an error message?
    (3) After you do that, assuming you didn't get an error message, does that new record appear in the table?
    Results:
    (1) the DEBUG did not print or echo out. (?) don't know why, looks right to me.
    (2) no error messge
    (3) yes, a new 0 appears in the table. in fact i ran it a bunch of times and "HOOAH" i got a whole string of 0's in the db table like it should be. all with new primary key's and with unique TIMESTAMP's. i say again "HOOAH"
    in fact i ran 0,0,0,1,2,3,0,0,0,4,5,6,0,0,0,1,2,3,0,1,0,1,0,1
    and they all matched up in the db just fine.

    and if i do the query in phpmyadmin the latest 3 enteries come out just fine.

    so what is the difference betix your code and mine?
    i really don't understand.
    mechanically it looks identical (sorta).
    yours guarantees passing the argument thru the url?querystring,
    where as mine is supposed to do the same thing, according to ajax syntax, but it appears mine is getting lost enroute to grandpas farm somehow.
    and why the $sql just to hold the INSERT INTO string?
    does that make a difference?
    i assume the "mysql_query( $sql ) or die( mysql_error() );" sets up an error msg in case the process fails (?).

    one more small question: your right, $data is an integer, not a string, slopiness is NOT ALLOWED. but if so (integer) then why $_GET['dataOut'];
    isn't that a string?

    i'm all yours MASTER,
    you've certainly got my attention.

    thank you,
    Paul

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,620
    Thanks
    78
    Thanked 4,388 Times in 4,353 Posts
    Last question first:

    $_GET["dateOut"]

    the ARGUMENT to the $_GET must be the *NAME* of the querystring variable you are asking for.

    Names are of course always strings.

    *********

    I only put the "INSERT ... " into the variable $sql so that I *could* debug it, by using the echo.

    If you aren't seeing the results of that echo--and/or if you aren't seeing the results of the fineal echo $data; then something is really really weird on your system.

    **********

    The fact that my PHP page is indeed adding more values to your table and the AJAX call is not begins to make me suspicious that something is wrong in the jQuery AJAX coding. But since I don't use jQuery, I think you will have to ask a jQuery expert what might be wrong. Maybe you aren't specifing the data value correctly? Maybe it's expecting a JSON object instead of a string?

    UPDATE: Nope, I think the string is okay.
    http://api.jquery.com/jQuery.get/
    says data can be *either* a map or string. Hmmm...maybe your string isn't in the right format?

    You might be better off using the JSON format for the data as shown in the examples on that page.
    Code:
           $.get('putRangeStatus-server-script.php', { "dataOut" : 1 }, processResponse);
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #15
    New Coder
    Join Date
    Dec 2011
    Posts
    59
    Thanks
    51
    Thanked 1 Time in 1 Post
    Old Pedant,
    thank you kindly.

    first i'm going to re.download the latest version of apache.server to ensure that my php code will run correctly.
    it does seem odd that echo "DEBUG SQL: " + $sql + "<hr/>"; wont work
    yet echo $data; does work.

    also i'm going to re.download MySQL just to be sure nothing is corrupt.

    thanks for the explaination

    i'll try Json format on the $.get() cmd.
    interesting the difference.
    Code:
    mine   $.get('putRangeStatus-server-script.php',   'dataOut=1',     processResponse);
    yours  $.get('putRangeStatus-server-script.php', { "dataOut" : 1 }, processResponse);


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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