Jump to content

cmazur

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

cmazur's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thanks, I'll take into consideration the suggestions you've made. Any other thoughts?
  2. Hey All, I've got some code that constantly updates a table on my web page. There is an update every 250 milliseconds. The problem is that my memory usage for IE is outrageous after about 5 minutes of running (roughly 600 mb of memory used). I'm not sure if this is a problem with my PHP script that pulls the data or the use of Sajax. My code is below: PHP Script to pull data: <?php require("Sajax.php"); session_start(); //Execute a SQL query and return a row function execute_mysql($sql) { //Connect to Database $db_host = "host"; $db_user = "username"; $db_pass = "password"; $db_name = "table"; $link = mysql_connect( $db_host, $db_user, $db_pass ); if(!$link) { unset($link); return -1; //database connection failed } else { $db_selected = mysql_select_db( $db_name ); if(!$db_selected) { mysql_close($link); unset($link); unset($db_selected); return -1; //database not selected } $res = mysql_query( $sql ); if(!$res) { mysql_close($link); unset($link); unset($db_selected); unset($res); return -1; //bad query } if(mysql_num_rows($res) == 0) { mysql_close($link); unset($link); unset($db_selected); unset($res); return -1; //empty query results } $row = mysql_fetch_assoc($res); mysql_close($link); unset($link); unset($db_selected); unset($res); return $row; } } //All 12 of the functions to be exported are in this format // They just pull different data function f1() { $sql = "SELECT STATEMENT;"; $row = execute_mysql($sql); echo "$row['col2']"; unset($sql); unset($row); } //Setup the Ajax sajax_init(); sajax_export("f1"); sajax_export("f2"); sajax_export("f3"); sajax_export("f4"); sajax_export("f5"); sajax_export("f6"); sajax_export("f7"); sajax_export("f8"); sajax_export("f9"); sajax_export("f10"); sajax_export("f11"); sajax_export("f12"); sajax_handle_client_request(); ?> The code the contains the Javascript for the calling of the functions and the timer event <script type='text/javascript'> <?php sajax_show_javascript(); ?> var secs; var timerID = null; var timerRunning = false; var delay = 250; function InitializeTimer() { secs = 1; StopTheClock(); StartTheTimer(); } function StopTheClock() { if(timerRunning) clearTimeout(timerID); timerRunning = false; secs = 1; } function StartTheTimer() { if(secs == 1) { <?php //Set the initial values f1(); f2(); f3(); f4(); ?> } //document.getElementById("divMem").innerHTML = "<?php echo memory_get_usage(false); ?>"; //self.status = secs + " Updates Performed"; secs = secs + 1; timerRunning = true; x_f1(f1_cb); x_f2(f2_cb); x_f3(f3_cb); x_f4(f4_cb); x_f5(f5_cb); x_f6(f6_cb); x_f7(f7_cb); x_f8(f8_cb); x_f9(f9_cb); x_f10(f10_cb); x_f11(f11_cb); x_f12(f12_cb); timerID = self.setTimeout("StartTheTimer()", delay); } function f1_cb(f1) { var temp = f1; if(temp != -1) document.getElementById("lblF1").innerHTML = temp; }
  3. Hey All, I've got some code that constantly updates a table on my web page. There is an update every 250 milliseconds. The problem is that my memory usage for IE is outrageous after about 5 minutes of running (roughly 600 mb of memory used). I'm not sure if this is a problem with my PHP script that pulls the data or the use of Sajax. My code is below: PHP Script to pull data: <?php require("Sajax.php"); session_start(); //Execute a SQL query and return a row function execute_mysql($sql) { //Connect to Database $db_host = "host"; $db_user = "username"; $db_pass = "password"; $db_name = "table"; $link = mysql_connect( $db_host, $db_user, $db_pass ); if(!$link) { unset($link); return -1; //database connection failed } else { $db_selected = mysql_select_db( $db_name ); if(!$db_selected) { mysql_close($link); unset($link); unset($db_selected); return -1; //database not selected } $res = mysql_query( $sql ); if(!$res) { mysql_close($link); unset($link); unset($db_selected); unset($res); return -1; //bad query } if(mysql_num_rows($res) == 0) { mysql_close($link); unset($link); unset($db_selected); unset($res); return -1; //empty query results } $row = mysql_fetch_assoc($res); mysql_close($link); unset($link); unset($db_selected); unset($res); return $row; } } //All 12 of the functions to be exported are in this format // They just pull different data function f1() { $sql = "SELECT STATEMENT;"; $row = execute_mysql($sql); echo "$row['col2']"; unset($sql); unset($row); } //Setup the Ajax sajax_init(); sajax_export("f1"); sajax_export("f2"); sajax_export("f3"); sajax_export("f4"); sajax_export("f5"); sajax_export("f6"); sajax_export("f7"); sajax_export("f8"); sajax_export("f9"); sajax_export("f10"); sajax_export("f11"); sajax_export("f12"); sajax_handle_client_request(); ?> The code the contains the Javascript for the calling of the functions and the timer event <script type='text/javascript'> <?php sajax_show_javascript(); ?> var secs; var timerID = null; var timerRunning = false; var delay = 250; function InitializeTimer() { secs = 1; StopTheClock(); StartTheTimer(); } function StopTheClock() { if(timerRunning) clearTimeout(timerID); timerRunning = false; secs = 1; } function StartTheTimer() { if(secs == 1) { <?php //Set the initial values for the bytes and packets of each feed f1(); f2(); f3(); f4(); ?> } //document.getElementById("divMem").innerHTML = "<?php echo memory_get_usage(false); ?>"; //self.status = secs + " Updates Performed"; secs = secs + 1; timerRunning = true; x_f1(f1_cb); x_f2(f2_cb); x_f3(f3_cb); x_f4(f4_cb); x_f5(f5_cb); x_f6(f6_cb); x_f7(f7_cb); x_f8(f8_cb); x_f9(f9_cb); x_f10(f10_cb); x_f11(f11_cb); x_f12(f12_cb); timerID = self.setTimeout("StartTheTimer()", delay); } function f1_cb(f1) { var temp = f1; if(temp != -1) document.getElementById("lblF1").innerHTML = temp; }
  4. Javascript: function getText_cb(getText) { document.getElementById("lblText").innerHTML = getText; } Php: function getText() { echo "This is the text"; } I figured it out. The problem was that I didn't have the right syntax when I was trying to call the callback function (getText_cb). The call should've been x_getText(getText_cb) instead of getText_cb(); If my function getText()took arguments, then then syntax would look like this: x_getText(arg1, arg2, getText_cb); Thanks again.
  5. php_tom, What you've said seems to work, however, this gets away from using AJAX (the Sajax toolkit). I believe the syntax should've been right because I've used code similar before. Any other ideas? Thanks, Chris
  6. Hey Guys, I'm having trouble getting the correct values back to my webpage. I'm using PHP and JavaScript along with SAJAX. The value of the text that is getting set in the label on my html page is "undefined". Here's the code. Javascript: function getText_cb(getText) { document.getElementById("lblText").innerHTML = getText; } Php: function getText() { echo "This is the text"; } Any ideas? Thanks, Chris
  7. ok, that was simple. thanks for all of the help.
  8. top of the page meaning that i need a php script in the header of my XHTML or at the top of the body of my XHTML? just a little confused. thanks for the help.
  9. Ok, I need to keep the username and user_id of my user who has logged in. This is my first attempt at using sessions, thus I am not sure why this is not working. The first time the user logs in, any old sessions are destroyed and a new session is started setting the username and id. When the user returns to the page , the username and id should be stored in the session array. Needless to say, I think it's my syntax having to do with the sessions... [code] if (isset($_POST["login"])) { //Get form data values $username = $_POST["username"]; $password = $_POST["password"]; //Validate the user $id = validate_user(get_user($username, $password), $username); if($id != -1) { //Unset any prior session variables unset($_SESSION['username']); unset($_SESSION['id']); //Destroy any prior session session_destroy(); //Start new session session_start(); $_SESSION['username'] = $username; $_SESSION['id'] = $id; } } else { //Get the logged in user's information session_start(); $username = $_SESSION['username']; $id = $_SESSION['id'];                                       print("user: $username <br />id: $id<br />");                           } [/code]
  10. Well, thanks again for your help. I'm going to toy around with this for a bit and see if I can get it all to work.
  11. ok, i think i got ya for the most part... just one more quick question while this thread is still goin': since my users have to login using a username and password, how could i save a variable that says that a user is logged in? would a cookie be goood enough? or is there an alternative method that would work better/be easier? thanks again for all of the help... p.s. i just love assignments when profs leave ya hangin' and don't respond to any questions sent via email...
  12. Kind of, Can action property be set to itself (my initial page is a php script with imbedded XHTML)? Then each time the page loads, I can see if data has been submitted and do what I need to do before i display the page? but to answer your question, I'm with you thus far. Thanks again for the help...
  13. ok, I'll be honest, you lost me...
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.