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

Recommended Answers

All 4 Replies

where did you set your $_SESSION["show"]?

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

Dan

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'];

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'];
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.