开发者

In PHP, How would I use a variable that was created in another php page?

I have an included page to the main index page, in the included page it has buttons to click on..i want to give these buttons a variable and when someone clicks on it, I can keep track of what button they selected in another page, w开发者_运维百科hich will show information for the selected button/variable...

Any ideas?


Well there is several ways to do this, but the main question is are you using a form button or a image button or a link or what?

Form:

HTML:

<form name="phpForm" action="myFile.php" method="get">
  <input type="submit" name="button" value="1">
  <input type="submit" name="button" value="2">
</form>

PHP:

<?PHP 
  echo $_GET["button"]; //either 1 or 2
?>

Image:

HTML:

<a href="myFile.php?button=1"><img src="whoo.png" /></a>
<a href="myFile.php?button=2"><img src="hilarious.png" /></a>

And the PHP above will also work with this.


You should really start reading a basic PHP tutorial.

Depending on what form is the method, you'll receive the variables in either $_POST or $_GET:

Use this code to find out

print_r($_GET);
print_r($_POST);


Welcome to web programming, this should get you started: http://www.w3schools.com/php/php_intro.asp


There are several ways of doing this you can either use GET, POST, or store the variable in a SESSION

I am assuming when user clicks the button it is directed to another page, if its true, then you can do a GET with http://yoursite.com/pageTo.php?data='hello' as the href that links to the button. Where pageTo.php would $_GET['data']


Insert the jquery code to try out the click counts:

$(document).ready(function(){
       var count =0;
      $('button').click(function(){
          count = count +1;
         $('#showcount').html('click count' + count);
             return false;
     });
});

and somewhere in your body make a div with id = ' showcount' to show the click counts.
Or you can then save the click count into a text file to look at...or whatever I hope this give you some ideas...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜