TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   global variables (http://www.talkphp.com/absolute-beginners/5240-global-variables.html)

reverse 01-29-2010 05:36 PM

global variables
 
Hi all,

I need help on this:
How do I pass a value from one variable to another variable upon users click?

example:
I have following html site

Code:

<html>
<head>
</head>
<body>

<?php
myGloablVarA=var1;
myGloablVarB=var2;
myGloablVarC=var3;
?>

<?php
some php codes here

how do make a function here (onclick) change those Global Variable defined above(myGloablVarA,myGloablVarB,myGloablVarC)
to new values thats been generated upon user click?

currently I am posting the value to url location

echo'<a href=\"detail.php?id=$var1.$var2.$var3\">

instead of posting the values to url location I
would like values to be stored in global varaibles and....
?>

<?php
.....read the values back here again

myVarnew1=myGloablVarA; // assign new values from myGloablVarA
myVarnew2=myGloablVarB;
myVarnew3=myGloablVarC;
?>
</body>
</html>


many thanks..I would be very glad on any tips
reverse

Village Idiot 01-29-2010 06:00 PM

You cant. PHP fully executes before the first character of information is sent to the user, so by the time they see it there is nothing running to switch. I also do not think you understand how global variables work. Global variables do not outlast the application which they are defined in, they are deleted along with everything else when the script finishes running.

andformore 01-30-2010 09:17 AM

some basics...
 
Village Idiot is, of course, right.

I've seen this type of logic from beginners before, and its pretty understandable. What I would recommend to help you better understand what is going on is to divide up your file into two sections, one where you're doing PHP work and the other where you're outputting HTML, sort of like this:

PHP Code:


<?php

//do all your data manipulation here
$someVar $someOtherVar;
$etc....

//then, below here you can put all your html
?>

<html>
<head>
</head>
<body>
<h1>this is an html page.</h1>
the value of a variable prepared above is <?php echo $someVar ?>.
</body>
</html>

Also, you should read a bit about how web servers work in general. The process is typically (for a php file) like:

1. a web user requests a page (www.example.com/myPhpFile.php)
2. the server runs the php file which creates html
3. the server sends that html back to the user who requested it
4. the user's browser turns that html into a working webpage
4. the user will click something which will either request a different page, or it will send a request along with some data. The server will handle that data and then send back the resulting html again.

You'll want to send the data using forms for now
If you let us know a bit more concretely what you want to accomplish we can help a bit more :-)


All times are GMT. The time now is 11:24 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0