$_GET

I have a [php]$_GET[‘status’][/php] variable and a dropdown list : [php]$_GET[‘amount’][/php].

Every time i click on a link. For example : Spullen Aangeboden .

I have to do this :

[php]if($_GET[‘amount’] != “”)
$amount = “&amount=”.$_GET[‘amount’];
else
$amount = “”;

if($_GET[‘status’] != “”)
$stat = “&status=”.$_GET[‘status’];
else
$stat = “”;[/php]

Spullen Aangeboden

So for every link I have to reset this. Is there another way to make it stay the last set value ?

You can do it with the $_POST of your select boxes name and just set the value to what was selected previously…

But their’s really no automatic way of doing it in php that I’m aware of. If you were using Microsoft .NET you just turn on viewstate and it will retain it for you automatically.

I’m not entirely sure what the problem is, but perhaps you can look into these options

Using $_REQUEST instead of $_GET

Using http_build_query()

Using $_SERVER[‘QUERY_STRING’]

What I mean is this: When I have a dropdown list with the name ‘amount’ with a standard value of ‘24’ and I change the value to 12. Then the value should stay 12 if I click on a link : a href="indexbody.php. But when I click on this link the value of the dropdown list is reset back to 24. So for every link I click, I have to do this :

[php]if($_GET[‘amount’] != “”)
$amount = “&amount=”.$_GET[‘amount’];
else
$amount = “”;
[/php]

a href=“indexbody.php?$amount”

Do you understand me ?

You want this:

[php]

<?php if (isset($_GET['amount'])){ echo "{$_GET['amount']} "; } ?> var1 var2 [/php]

Another way of doing it.
[php]<?php echo (isset($_GET['amount'])) ? '' . '$' . number_format($_GET['amount'], 2) . '' : NULL; ?>[/php]

I have this right now :

[php]function setNumberPerPage($id) {

$options = array(
			
			 6 => 6,
			12 => 12,
			18 => 18,
			24 => 24,
			30 => 30
		
);

if($_GET['service'] != "Info" && $_GET['service'] != "Bericht") {
	
	echo"<form name = 'form' action = 'indexbody.php' method = 'GET'>
	<label for = 'amount' id = 'label'>Aantal: </label>
	<select id='$id' name='amount' onchange='setAmount(this)'>";
	
	foreach($options as $key => $value) {
	 		
		$selected = $_GET['amount'] == $key ? 'selected' : '';
		if($key == 24 && !$_GET['amount'])
			$selected = 'selected';
								
		echo"<option value = '".$key."' ".$selected.">".$value."</option>";
	}
		
	echo"</select></form>";
}			

}[/php]

[code][/code]

What should I change to make it work ?

amount is the name of the dropdown list, not mydropdown !

Sorry dude but your solution doesn’t work ! My code, you see above, works. The only problem is, when I have a link : indexbody.php?service=test1&amount=12. Amount is the name of the dropdown list with a standard value of 24! And if I have another link : indexbody.php?service=test2 witch doesn’t set amount. If I click on the second link, the dropdown list is reset back to 24.

So for every link i have to reset the URL parameter amount : indexbody.php?service=test2&amount=12. Isn’t there a way it automatically stays 12 ?

Thank you !

Post the entire code you are using.

This is my indexbody.php !

[php]<?php
require_once("…/.common/.init.php");

$style = ‘…/.common/default.css’;
$ip = $_SERVER[‘REMOTE_ADDR’];
//if ($ip != $status_ip1 and $ip != $status_ip2 and $ip != $status_ip3) {$status = ‘sorry’;}

$db = new PDO(DBASE);
$result = $db->query(“SELECT * FROM Teksten WHERE soort=‘adres’;”);
foreach($result as $row)
{ extract($row); $adres = $tekst;}

$telefoon = ‘Vragen? Bel ons! (dinsdag t/m vrijdag tussen 10 en 16 uur)’;
$nwsbrief = “…/nieuwsbrief/print.php”;
$nwsbriefbeheer = $nwsbrief."?status=1234";
$omschrijvingRW = <<< OMSCHR
Bij de Ruilwinkel helpen we elkaar met spullen en diensten.
De waardering gaat in punten, geld speelt geen rol.
U kunt punten verdienen door andere deelnemers te helpen, met spullen die u zelf over hebt, of door een klusje op te knappen.
Met de verdiende punten kunt u zelf spullen afnemen of hulp vragen bij dingen waar u zelf minder goed in bent.
Dankzij de punten is ruilen met gelijk oversteken niet nodig!
OMSCHR;

function setHeader() {
extract($GLOBALS);

if($_GET['amount'] != "")
$amount = "&amount=".$_GET['amount'];
else
$amount = "";
if($status == $statuscode) {

echo "<div id='header' style='width: 1010px; height: 85px; background-color: #4B259C;'>
<h2 style='position: absolute; margin-left: 30px; margin-top: 32px; color: white'>BEHEER</h2>
<a href = '../paginas/indexbody.php?status=1234$amount' target = '_top' ><img style='position: absolute; margin-left: 780px; margin-top: 15px; width: 180px; height: 50px;' src='../.common/ruilwinkel.gif' title='$omschrijvingRW' border='0'/></a>
<a href='$nwsbriefbeheer' target='_blank'><img style='position: absolute; margin-left: 540px; margin-top: 2px' src='../.common/nwsbrief.gif' title='laatste nieuwsbrief' border='0'/></a>
<div style= 'position: absolute; margin-left: 200px; margin-top: 8px; width: 500px; color: White; text-align: left;' title='Zie ook kaartje onderaan deze website'>$adres</div>
</div>";
}
else {
		
echo "<div id='header' style='width: 1010px; height: 85px; background-color: #4B259C;'>
<a href='indexbody.php?service=Bericht$amount' style='position: absolute; margin-left: 700px; margin-top: 12px; '><img src='../images/brief.gif' border='0' title='mail ons! Klik hier voor contact-formulier' /></a>
<img style='position: absolute; margin-left: 5px; margin-top: 3px; width: 40px; height: 40px;' src='../.common/logo.gif' title='$omschrijvingRW' border='0'>";
if($amount != "")
$amount = str_replace('&','', '?'.$amount);
echo"<a href = '../paginas/indexbody.php$amount' target = '_top' ><img style='position: absolute; margin-left: 45px; margin-top: 8px; width: 140px; height: 36px' src='../.common/ruilwinkel.gif' title='$omschrijvingRW' border='0'/></a>
<h6 style='position: absolute; margin-left: 45px; margin-top: 54px;' title = '$telefoon'>010-2151657</h6>
<a href='$nwsbrief' target='_blank'><img style='position: absolute; margin-left: 850px; margin-top: 10px; width: 135px; height: 60px;' src='../.common/nieuws.gif' title='laatste nieuws' border='0'/></a>
<div style= 'position: absolute; margin-left: 200px; margin-top: 8px; width: 500px; color: White; text-align: left;' title='Zie ook kaartje onderaan deze website'>$adres</div>
</div>";
}

}

function setServTitel() {
extract($GLOBALS);
if(!isset($_GET[‘service’]))
$_GET[‘service’] = “Spulaanbod”;

switch($_GET['service'])
{
case "Spulaanbod": echo $status == $statuscode ? "<a class='beheer' href = 'indexbody.php'>+</a>" : ""; echo"<span class='title'>Spullen Aangeboden</span>";break;
case "Spulgevraagd": echo "<span class='title'>Spullen Gevraagd</span>";break;
case "Hulpaanbod": echo "<span class='title'>Hulp Aangeboden</span>";break;
case "Hulpgevraagd": echo "<span class='title'>Hulp Gevraagd</span>";break;
case "Leenaanbod": echo "<span class='title'>Te Leen Aangeboden</span>";break;
case "Info":echo "<span class='title'>Info</span>";break;
case "Bericht": echo "<span class='title'>Bericht Versturen</span>";break;
}

}

function setService() {

extract($GLOBALS);
switch($_GET['service'])
{
case "Spulaanbod": include '../paginas/nwspul.php';break;
case "Spulgevraagd": include'../paginas/vraag.php';break;
case "Hulpaanbod": include'../paginas/dienstenA.php';break;
case "Hulpgevraagd": include'../paginas/dienstenV.php';break;
case "Leenaanbod": include '../paginas/uitleen.php';break;
case "Bericht": include '../paginas/bericht.php';break;
}

}

function setServices() {
extract($GLOBALS);
include ‘…/paginas/services.php’;
}

function setPages() {

extract($GLOBALS);
if(!isset($_GET['page']))
	$_GET['page'] = 1;
	
switch($_GET['service'])
{
case "Spulaanbod": $result = $db->query("SELECT COUNT(*) AS Aantal FROM AanbodSpul;");break;
case "Spulgevraagd": $result = $db->query("SELECT COUNT(*) AS Aantal FROM Vraag;");break;
case "Hulpaanbod": $result = $db->query("SELECT COUNT(*) AS Aantal FROM DienstenA;");break;
case "Hulpgevraagd": $result = $db->query("SELECT COUNT(*) AS Aantal FROM DienstenV;");break;
case "Leenaanbod": $result = $db->query("SELECT COUNT(*) AS Aantal FROM Uitleen;"); break;
}

if($_GET['service'] != "Info" && $_GET['service'] != "Bericht") {
foreach($result as $row)
{ extract($row); }

$_GET['pages'] = ceil($Aantal/$page_limit);

if($_GET['pages'] == 0)
	$_GET['pages'] = 1;
	
echo "<span id='pages'>Pagina ".$_GET['page']." van ".$_GET['pages']."</span>";
}

}

function setButtons() {

$page = $_GET['page'];
$pages = $_GET['pages'];
$serv = $_GET['service'];

if($_GET['amount'] != "")
$am = "&amount=".$_GET['amount'];
else
$am = "";

if($_GET['status'] != "")
$stat = "&status=".$_GET['status'];
else
$stat = "";

if($page > 1) {
echo"<a class='a' href='indexbody.php?service=$serv&page=1$am$stat'><div id='first'>|< </div></a>";
echo"<a class='a' href='indexbody.php?service=$serv&page=".($page - 1)."$am$stat'><div id='previous'> < </div></a>";
}

if($pages > 10)
$left_range = 8;
else
$left_range = 9;

if($page >= 10)
$right_range = 1;
else
$right_range = 10 - $page;
		
for($i = ($page - $left_range) ; $i <= ($page + $right_range); $i++) {
	
	if($i > 0 && $i <= $pages) {		
		if($page == $i)
		echo"<a class='a'><div id='selected'>$i</div></a>";
		else
		echo"<a class='a' href='indexbody.php?service=$serv&page=$i$am$stat'><div id='p'>$i</div></a>";
	}
		
}

if($page < $pages) {
echo"<a class='a' href='indexbody.php?service=$serv&page=".($page + 1)."$am$stat'><div id='next'> > </div></a>"; 
echo"<a class='a' href='indexbody.php?service=$serv&page=$pages$am$stat'><div id='last'> >| </div></a>";
}

}

function setNumberPerPage($id) {

$options = array(
			
			 6 => 6,
			12 => 12,
			18 => 18,
			24 => 24,
			30 => 30
		
);

if($_GET['service'] != "Info" && $_GET['service'] != "Bericht") {
	
	echo"<form name = 'form' action = 'indexbody.php' method = 'GET'>
	<label for = 'amount' id = 'label'>Aantal: </label>
	<select id='$id' name='amount' onchange='setAmount(this)'>";
	
	foreach($options as $key => $value) {
	 		
		$selected = $_GET['amount'] == $key ? 'selected' : '';
		if($key == 24 && !$_GET['amount'])
			$selected = 'selected';
	  

		echo"<option value = '".$key."' ".$selected.">".$value."</option>";
	}
	
	echo"</select></form>";
}			

}

if($_GET[‘amount’] != “”)
$amount = “&amount=”.$_GET[‘amount’];
else
$amount = “”;

if($_GET[‘status’] != “”)
$stat = “&status=”.$_GET[‘status’];
else
$stat = “”;

$menu = <<< MENU

MENU;

echo <<< START

Test

START;
?>

<? echo "
"; setHeader(); echo "
$menu
";setServTitel(); echo" ";setNumberPerPage("amount1"); echo" ";setPages(); echo" ";setButtons(); echo"
";setService(); echo "
";setServTitel(); echo" ";setNumberPerPage("amount2"); echo" ";setPages(); echo" ";setButtons(); echo"
";setServices(); echo "
$menu
Copyright © 2013 Fijenoord Ruilwinkel
"; ?>[/php]

Kevin ?

Your code is not working because you are not using brackets with your if/else statements so you have multiple encapsed whitespace errors. You need to either use brackets or enclose the variables that need it in brackets.

The brackets have nothing to do with it.

The brackets and lack thereof has everything to do with it.

Show me this code working without adding additional brackets anywhere. Not going to happen.

Sponsor our Newsletter | Privacy Policy | Terms of Service