Jump to content

doulbe $_GET


arbitter

Recommended Posts

How do you put in multiple $_GET 's? But they're not from a form or anything, just by clicking on links...

So say you first select an album, the phpfile url gets: .php?album=choice

Then, If you select a way of order of the pictures, the url goes: .php?sort=choice

 

I need to get both of them in the URL, so I need to get .php?album=choice&sort=choice

How do I reach this? Can you do this without a form like

<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

?

 

Link to comment
Share on other sites

<?php

///// functions /////

function myFirst(){
    echo 'The First ran successfully.';
}

function mySecond(){
    echo 'The Second ran successfully.';
}

///// START /////

?>
<html><body>

<?php

if (isset($_GET['run'])) $linkchoice=$_GET['run'];
else $linkchoice='';

switch($linkchoice){

case 'first' :
    myFirst();
    break;

case 'second' :
    mySecond();
    break;

default :
    echo 'no run';

}

?>
<hr>
<a href="?run=first">Link to First</a>
<br>
<a href="?run=second">Link to Second</a>
<br>
<a href="?run=0">Refresh No run</a>

</body></html>

 

See how this works? You need to do that for your code

Link to comment
Share on other sites

I don't really understand completely, but I think it does not do what I wish it to do...

Because If I select the first one, it does the first one, if I select the second, it does the second. But it has to be that if I choose the second one, nothing really happens seen there's nothing to sort yet. If I then click the first one, the albums show and if I click the second one then the albums get show in (another) order.

Link to comment
Share on other sites

How do you put in multiple $_GET 's? But they're not from a form or anything, just by clicking on links...

So say you first select an album, the phpfile url gets: .php?album=choice

Then, If you select a way of order of the pictures, the url goes: .php?sort=choice

 

I need to get both of them in the URL, so I need to get .php?album=choice&sort=choice

How do I reach this? Can you do this without a form like

<form action="welcome.php" method="get">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>

?

 

 

Possibilites

using form

<form action="mypage .php?album=choice&sort=choice" method="get">

 

usign link

<a href='mypage.php?album=choice&sort=choice'>

 

or best way to do this in form

<hidden name=sort value=choice>

<hidden name=album value=choice>

 

 

i dont thing there is any other way to do this

Link to comment
Share on other sites

I'm having a problem with the links though..

 

First I have:

echo "<tr><td style='cursor:pointer;cursor:hand' onclick=\"location.href='?month=$qmap'\"><center>$map</td></tr>";

 

Seen that all the maps that are displayed come through a foreach because it's variable.

Then when you click on it, in the right hand side of the page all the images in that directory, the $map directory, get shown.

 

Then I have:

<tr valign='bottom'><td style='cursor:pointer;cursor:hand' onclick=\"location.href='?month=$qmap&?sort=ksort'\"><center>Oldest</td>
				<td style='cursor:pointer;cursor:hand' onclick=\"location.href='?month=&?sort=knsort'\"><center>Newest</td></tr>";

 

So if I do $sorttype = $_GET['sort'], I should get 'knsort' or 'ksort', no?

It doesnt really work though, and also it changes the folder $map it's in...

Link to comment
Share on other sites

Hm? $_GET is a superglobal for url passed variables. You'd change:

?month=$qmap&?sort=ksort

To:

?month=$qmap&sort=ksort

 

Therefor, you can access them via $_GET['month'] and $_GET['sort'] respectively. ? is an operator to tell the url there is going to be a $_GET variable, file.php?var1=foo&var2=bar&var3=baz

Link to comment
Share on other sites

Thank you for your reply.

I've changed it now, to:

<td onclick=\"location.href='?month=$qmap&sort=$sort'\">$map</td>

<td style='cursor:pointer;cursor:hand' onclick=\"location.href='?month=$qmap&sort=ksort'\">Oldest</td>

 

but unfortunately it still goes to the last map, not the selected map... And something else is wrong to in my code;

$sort = $_GET["sort"];
			$month = $_GET["month"];
			if (isset($month)){
				$images = glob($month . '/*.{jpg,gif,jpeg,pjpeg,image,JPEG}', GLOB_BRACE|GLOB_NOSORT);
				if (isset($images)){
					foreach ($images as $image)
						{$sortedimages[filemtime($image)] = $image; }
					if ($sort = ksort){
						ksort($sortedimages);
						foreach (($sortedimages) as $afbeelding)
							{ echo "</br><center><img src=\"$afbeelding\" style=\"max-width: 60%\"></br>";}}
					else {knsort($sortedimages);
						foreach (($sortedimages) as $afbeelding)
							{ echo "</br><center><img src=\"$afbeelding\" style=\"max-width: 60%\"></br>";}}}}

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.