如果php for mysql中的get值为0,如何设置变量?

I am passing variables in a url to a new php page and want to set an array if the variable value = 0.

The code used to pass the variable is:

?type=2

My get statement looks like this:

$type = intval($_REQUEST['type']);

if ($type = 0)
$itype = array(2,3);
else
$itype = $type;

I am then trying to use {$itype} in my SQL query like this:

AND cid IN ({$itype})

The result I need is when the value is 0 like:

?type=0

the query to be:

AND cid IN (2,3)

and if the value is 2 like:

?type=2

the query to be:

AND cid IN (2)

This is my solution but I am not sure my methodology is sound. Your help would be greatly appreciated.

first of all, you should change this line :

if ($type = 0) // this assigns 0 to $type

to this line

if ($type == 0) // this checks if $type == 0

then, you can change your sql query like this:

$sql_query = "bla bla AND cid IN " . ($type==0 ? "(2,3)" : "(2)") ." bla bla";