Question

Ive created a dropdown list which passes its value using GET to a php value. if i just echo this value then it changes every time the dropdown is changed, however when i try use this value in an if statement it always uses the echo option given from the top value

<form action="" align="center" method ="get">
<select name="mylist" onChange="this.form.submit()">
<option>Filter By Team</option>
<option value="1">All Players</option>
<option value="2">Micros</option>
<option value="3">U7s</option>
</select>
</form>

<?php
$team = $_GET["mylist"];
if ($team="1") {
  echo "Filtering for All Players";
} elseif ($team="2") {
  echo "Filtering for 2";
} else {
  echo "Filtering for 3";
}

is the code i am using

thanks for your help

Was it helpful?

Solution

You are presently assigning using a single = sign, instead of comparing using 2x == signs.

if ($team==1) {
  echo "Filtering for All Players";
} elseif ($team==2) {
  echo "Filtering for 2";
} else {
  echo "Filtering for 3";
}

For more information on assignment operators, visit PHP.net

and on comparison operators

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top