arbitter Posted January 16, 2010 Share Posted January 16, 2010 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> ? Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/ Share on other sites More sharing options...
ShadowIce Posted January 16, 2010 Share Posted January 16, 2010 you can do it, but it would require you to put "albumchoice" & "sort" into a php function Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996166 Share on other sites More sharing options...
arbitter Posted January 16, 2010 Author Share Posted January 16, 2010 Could you please be more specific? I'm really new te php, and I'm not so smooth in all of this... Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996169 Share on other sites More sharing options...
ShadowIce Posted January 16, 2010 Share Posted January 16, 2010 <?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 Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996172 Share on other sites More sharing options...
arbitter Posted January 16, 2010 Author Share Posted January 16, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996182 Share on other sites More sharing options...
hamza Posted January 16, 2010 Share Posted January 16, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996197 Share on other sites More sharing options...
arbitter Posted January 17, 2010 Author Share Posted January 17, 2010 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... Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996567 Share on other sites More sharing options...
oni-kun Posted January 17, 2010 Share Posted January 17, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996569 Share on other sites More sharing options...
arbitter Posted January 17, 2010 Author Share Posted January 17, 2010 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>";}}}} Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996573 Share on other sites More sharing options...
oni-kun Posted January 17, 2010 Share Posted January 17, 2010 Your code is incorrect. if ($sort = ksort){ That is assigning. == is comparison. and it's not in a string as well! if ($sort == 'ksort'){ ... Is what you should do from now on, you should start by fixing your code. Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996574 Share on other sites More sharing options...
arbitter Posted January 17, 2010 Author Share Posted January 17, 2010 Fixed that. Seems to be working fine now, only problem is still that of I click one of the 'sort' buttons, it automatically goes to the last album... so the $month changes for some reason... But the sorting goes well. Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-996737 Share on other sites More sharing options...
arbitter Posted January 18, 2010 Author Share Posted January 18, 2010 Anyone with any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/188707-doulbe-_get/#findComment-997437 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.