Ads Posted November 27, 2007 Share Posted November 27, 2007 What I want to do is When you Click a link in an Iframe it Updates a Variable being displayed in the main page. here is the Code for the page in. <?php session_start(); include("include/db.php"); $username = $_SESSION['username']; echo $username; $energy = $row['energy']; $newenergy =$energy-1; $sql="update players set energy='$newenergy' where username='$username'"; $result= mysql_query($sql); echo $newenergy; ?> <html> <head> <title>.::Cyrus Lite::.</title> <link href="style.css" rel="stylesheet" type="text/css"> </head> <body> The Variable in the Main page is the $energy Variable also. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 so, let me get this straight, you want to click a link and have the sql requery? once the php is done with a page the vars are scrubbed, so by the time your are clicking on the browser $energy variable is a forgotten memory to PHP. . Now if you want to click on a link and have something dynamic happen in parent document you will need to use AJAX Quote Link to comment Share on other sites More sharing options...
Ads Posted November 27, 2007 Author Share Posted November 27, 2007 I want $energy to update on both Pages, Without having to Reload Both. Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 as i said before. $energy is gone. php resides on the server and the link you click is in your local browser, there is no connection and no persistence of state, between server and browser. so now that we have that clear. Ok, to dynamically alter what the output that $energy is possible thru Javascript. but remember that Javascript is local browsers and any changes that transpire will not reflect on server db, unless you use AJAX to send the update to the database. so lets say you have a this parent window <span id="energy"><? echo $energy ?></span> iframe <a href="javascript:void();" onclick="window.parent.getElementById('energy').value = 10;">set parent frame energy displayed value</a> note the when php ran the script it used $energy to place a value in parent output. you can see with the javascript I can only effect in the diplayed value span.energy object hope this gives you an understanding of the distance between the browser and the php server Quote Link to comment Share on other sites More sharing options...
Ads Posted November 27, 2007 Author Share Posted November 27, 2007 Okay Thats all cool, But When I Click The link, I want Energy to Decrease by 1 Every single Click Quote Link to comment Share on other sites More sharing options...
BenInBlack Posted November 27, 2007 Share Posted November 27, 2007 ok parent.php with iframe code <?php ob_start(); session_start(); $energy = 10; ?> <span id="energy"><? echo $energy ?></span> <hr> <IFRAME SRC="child.php" WIDTH=450 HEIGHT=100> If you can see this, your browser doesn't understand IFRAME. </IFRAME> child.php (contents of iframe <?php ob_start(); session_start(); ?> <a href="javascript:void(0);" onclick="reduceValue();">reduce parent value</a> <SCRIPT language="JavaScript"> <!-- Begin JavaScript var energy = 10 function reduceValue() { energy--; parent.window.document.getElementById('energy').innerHTML = energy; } // -- End JavaScript --> </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Ads Posted November 27, 2007 Author Share Posted November 27, 2007 Kool, But Wouldn't that be easy To Manipulate? And hack? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.