Page 1 of 1

refreshing page after a function call

Posted: Mon Jan 13, 2003 10:27 am
by cscrum
I have some text that calls a function when clicked. The function updates a value in an array. A number on the page then needs to be changed to reflect this new value. How do I refresh the page without resetting all the values of the array? Here is a sample of what is happening

Code: Select all

<?
session_start();
if (!isset($_SESSION['uid']) ) {
    $_SESSION['s_box']; 
?>

<?php 
Class Box {
var $addeditems;
function add_Remove($id,$qty) {  
    $this->$addeditems[$id] = $qty; 
     }
}
 

$s_box = new Box(); 
?>

<a HREF= "<?php echo ($PHP_SELF); ?>" onclick="<?php $s_box->add_Remove('state_dc','1'); ?>">ADD</a>

<a HREF= "<?php echo ($PHP_SELF); ?>" onclick="<?php $s_box->add_Remove('state_dc','-1'); ?>">Remove</a>

<?php
	if($addeditems['state_dc'] == 1){
?><td><? echo $addeditems['state_dc']; ?></td>
<?
}
?>
When I click "ADD" or "Remove" nothing happens. Any help would be appreciated.

Posted: Mon Jan 13, 2003 2:23 pm
by glo-wurm
I think you are confusing PHP to be a client-side language... PHP is server-side, not client-side. You'll need to read up on javascript first for this :P

Posted: Mon Jan 13, 2003 2:30 pm
by Rob the R
Do a View Source in your browser for the page this code is in. When the Add or Remove links are clicked, the action will be exactly what is in the HTML code in the View Source. Since PHP is a server-side language, no PHP code will be run unless the page is reloaded.

You would need to use Javascript to make a page interactive in the way you describe. There's a good treatment of this topic in one of the sticky-posts in this forum.