Jump to content

How can I update values after load


Chanpa

Recommended Posts

Hey,

I'm making sort of a betting system for me and my friends and I've run into a bit of a snag.

The first part of it is fairly easy it is a simple 1 x 2 betting system like this:

<?php
$grp_a_t1 = array("team" => "Sverige", "pts" => 0);
$grp_a_t2 = array("team" => "Norge", "pts" => 0);
$grp_a_t3 = array("team" => "Danmark", "pts" => 0);
$grp_a_t4 = array("team" => "Finland", "pts" => 0);
?>
Round 1
<?php echo $grp_a_t1["team"]." - ".$grp_a_t2["team"]; ?>
<select name="grp_a_r1_m1">
<option>1</option>
<option>x</option>
<option>2</option>
</select>
<?php echo $grp_a_t3["team"]." - ".$grp_a_t4["team"]; ?>
<select name="grp_a_r1_m2">
<option>1</option>
<option>x</option>
<option>2</option>
</select>

Now what I want to know how to do (if possible) is to update the $team["pts"] depending on what you select. For instance if you choose "1" in the first match(name="grp_a_r1_m1"), I want to do: $grp_a_t1["pts"] += 3;

I would prefer it to update as soon as you select something, however I will settle for "at the press of a button" if it turns out it's to hard to have it update instantly.

I'm pretty sure I can't make this with PHP alone, so Currently I have done this:

<button id="grp_a_upd">Update this group</button>
<div id="grp_a">
<?php echo $grp_a_t1["team"]." with ".$grp_a_t1["pts"]; ?><br />
<?php echo $grp_a_t2["team"]." with ".$grp_a_t2["pts"]; ?><br />
<?php echo $grp_a_t3["team"]." with ".$grp_a_t3["pts"]; ?><br />
<?php echo $grp_a_t4["team"]." with ".$grp_a_t4["pts"]; ?><br />
</div>
<script language="javascript" type="text/javascript">
$('#grp_a_upd').click(function() {
	// Is it possible to update the variables here?
});
</script>

So as is infered in the code snippet above, is it possible to update php-variables with jQuery like that? If it is, how? Or do I need AJAX?

 

Thanks,

Chanpa

Link to comment
https://forums.phpfreaks.com/topic/264270-how-can-i-update-values-after-load/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.