View Full Version : Add link ID into an Array

11-20-2007, 09:26 PM

I have a page containing 5 links, each link has a different ID number at the end. (Shown in Bold)

http://localhost/Memory.php?action=add&id=1 (http://localhost/Memory.php?action=add&id=1)
http://localhost/Memory.php?action=add&id=2 (http://localhost/Memory.php?action=add&id=2)
http://localhost/Memory.php?action=add&id=3 (http://localhost/Memory.php?action=add&id=3)
http://localhost/Memory.php?action=add&id=4 (http://localhost/Memory.php?action=add&id=4)
http://localhost/Memory.php?action=add&id=5 (http://localhost/Memory.php?action=add&id=5)

Each time a link is clicked, how do I add the id at the end of each link, to an array? But, if array already contains that particular ID, how do I display a message notifying the user e.g. "Already Added!"

Once in the array, how do I output the items in the array to the screen, along with a remove button.

Upon clicking the remove button, how do I delete the appropriate id from the array. The remove link will be in the form of the following:

http://localhost/Memory.php?action=delete&id=1 (http://localhost/Memory.php?action=delete&id=1)
http://localhost/Memory.php?action=delete&id=2 (http://localhost/Memory.php?action=delete&id=2)
http://localhost/Memory.php?action=delete&id=3 (http://localhost/Memory.php?action=delete&id=3)
http://localhost/Memory.php?action=delete&id=4 (http://localhost/Memory.php?action=delete&id=4)
http://localhost/Memory.php?action=delete&id=5 (http://localhost/Memory.php?action=delete&id=5)

11-20-2007, 09:40 PM
Look in the PHP manual for information on Arrays (http://www.php.net/manual/en/ref.array.php). There are plenty of ideas there.

11-21-2007, 08:12 AM
Just a tip, it's not good to name pages with capitals.

11-21-2007, 03:45 PM
There's nothing wrong with it.

It's a recommendation to keep the names all lowercaps because it's easier to not get it wrong.

11-21-2007, 05:40 PM
There's nothing wrong with it but it's not something you should do...?

Sounds like there's one thing wrong with it, if you shouldn't do it. ;)