Skip to main content
Inspiring
March 1, 2012
Question

Problem extracting variables passed through a url

  • March 1, 2012
  • 1 reply
  • 736 views

Hi I'm trying to pass two variables via a url which I can acheive, but I'm having trouble extracting the information when page refreshes.

This is the code I've used to pass the variables:_

<?php while ($row = mysql_fetch_assoc($result1)) {   ?>

<a href="<?php echo $_SERVER['PHP_SELF'];?>?gallery_id=<?php echo $row['gallery_id']; ?>&year_id=<?php echo $row['year_id'];?>"><?php echo $row['name']; ?></a>

<?php } ?>

I'm able to acheive the my objective when on variable is passed using the following code:-

if (array_key_exists('gallery_id', $_GET)) {

$gallery_id = $_GET['gallery_id'];

My question is, how do I do this with two (or more) variables? I need to extract $year_id as well.

Thanks.

This topic has been closed for replies.

1 reply

Inspiring
March 4, 2012

Have you considered using a session variable to store the values?

nicko2Author
Inspiring
March 4, 2012

Thanks for the reply.

No I hadn't considered this option, but since there is the ability for multiple variables to be sent through a url, it follows there must be a way of retreiving them using $_GET, I just can't figure out how to do it!  If anyone can point me in the right direction I would be most grateful

Thanks.

Participating Frequently
March 5, 2012

What happens when you try:

if (array_key_exists('year_id', $_GET)) {

$year_id = $_GET['year_id'];