...

View Full Version : Remember Array Contents



Zeater
11-21-2007, 07:17 PM
Hi,

I have the following code, that inserts the ID value of a link into an array, upon the link being clicked. See example link below:


www.somthing.co.uk/functions.php?id=23 (www.somthing.co.uk/functions.php?id=23)

How do I get the array to remember its contents, so if the browsers back button is used, and another link is clicked, this link should append/add it's id to whats already inside the array?

What do I need to change in the following code in order for the array to remember its contents:


<?php

$array[] = $id;
print_r($array);

?>

kbluhm
11-21-2007, 07:32 PM
Use sessions:


<?php

session_start();
$_SESSION['ids'][] = $id;
$array = & $_SESSION['ids'];

/* ... */

print_r( $array );

?>

Zeater
11-21-2007, 07:50 PM
The above code doesn't work, when I press the "Back" button on my browser, and select a link with a diffrent ID (or even the same ID) all I get is the following: - Wheres the data?

Array ( [0] => [1] => [2] => [3] => [4] => )

Inigoesdr
11-21-2007, 08:13 PM
Try using $_GET['id'] instead of $id. I don't think kbluhm intended for you to take that code literally, but more as an example.

Zeater
11-21-2007, 08:54 PM
How do I check is the array already contains a particular id, and if so display the following message "Already Exists", if not, then add it?

kbluhm
11-21-2007, 10:04 PM
http://www.php.net/in_array

psykx
11-22-2007, 03:10 PM
I'd use a cookie to store the data



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum