Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
Have you considered using a session variable to store the values?
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
What happens when you try:
if (array_key_exists('year_id', $_GET)) {
$year_id = $_GET['year_id'];
Copy link to clipboard
Copied
Thanks for the reply.
I get the following notice.
Notice: Unidentified index: gallery_id in ......
I'm trying to create a photo gallery that displays years at the top, the gallery names for the relevant year in the left hand pane and the relevant photos for a particular gallery in the right hand pane. I have nearly acheived the aim in that everything will initially display ok and when a different year is selected and the page reloads, it will list the galleries for that year and display the photos for the first gallery in the list.
The problem is that when a new gallery is selected I am able to pass the new gallery_id and the year_id when the page reloads, but I can't extract both results using If(array_key_exists and since the script needs both to function I'm a bit stuck.
What i really want to do is something like If(array_key_exists('year_id', 'gallery_id', $_GET)) {
but this won't work! Is it possible to do it this way or am I barking up the wrong tree?
Thanks.
Copy link to clipboard
Copied
OK, I have practically zero experience with PHP, but I'm not sure why you choose to use array_key_exists(). Most folks test for form values using isset()
if ((isset($_GET["year_id"]))
Try that instead, although I don't know why you are getting an error. We would need to see the complete code to tell that.
>If(array_key_exists('year_id', 'gallery_id', $_GET)
That would not work because array_key_exists() only acccepts 2 parameters. If you want to check if both values are set, you would need to combine the test of both using boolean AND..