0

Hey,

I have some php code that I cant seem to get working...
Here is the code...

This is the javascript that changed the ?show in the url to what the user selects..

<script type="text/javascript">
function show(){
	var e = document.getElementById("select");
	var strUser = e.options[e.selectedIndex].value;
	window.location = "?show="+strUser;
}
</script>

<select name="select" id="select" onchange="show();">
  <option value="<?php if(isset($_SESSION['show'])){ echo $_SESSION['show']; }else{ echo "16"; } ?>" selected="selected"><?php if(isset($_SESSION['show'])){ echo $_SESSION['show']; }else{ echo "16"; } ?></option>
  <option value="16">16</option>
  <option value="32">32</option>
  <option value="48">48</option>
  <option value="64">64</option>
</select>

PHP Code the works it out...
If both the session and the get are blank it needs to be 16 but if the session is blank but the get isnt set the session to the get value else if the get is blank but the session isnt get the session to the session...
(hope this makes sense)

if($_GET['show'] == NULL && $_SESSION['show'] == NULL){
	$_SESSION['show'] = "16";
}

elseif($_SESSION['show'] == NULL){
	$_SESSION['show'] = $_GET['show'];
}
else{
	$_SESSION['show'] = $_SESSION['show'];	
}

$max_results = $_SESSION['show'];

But it doesnt seem to be working on the PHP side...

Dan

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by twiss
0

in the last else statment the session is alreay set to it just resets it to iteself...

Dan

0

Fixed: I was over confusing things... This is the fixed code...

if($_GET['show'] != NULL){
	$_SESSION['show'] = $_GET['show'];
}else{
	if($_SESSION['show'] == NULL){
		$_SESSION['show'] = "16";
	}else{
		$_SESSION['show'] = $_SESSION['show'];
	}
}

$show = $_SESSION['show'];
0

As Danny159 said, line 7 doesn't make too much sense (it doesn't do anything, really). You could remove the else;

if($_GET['show'] != NULL) $_SESSION['show'] = $_GET['show'];
elseif($_SESSION['show'] == NULL) $_SESSION['show'] = '16';
$show = $_SESSION['show'];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.