问题
i want to select from database by url and for this i do this if:
if (isset($_GET['class']) == 'dw')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dw] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'bk')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [bk] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'fe')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [fe] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'mf')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [mf] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'dl')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dl] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'sum')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [sum] > 0 order by credits asc");
}
if (isset($_GET['class']) == 'rf')
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [rf] > 0 order by credits asc");
}
else
{
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' order by credits asc");
}
Url for this is: index.php?sy=items&class=dw
but when i access this url index.php?sy=items&class=dw
is selected last if :( : index.php?sy=items&class=rf
can help me to resolve for work with each if ?
回答1:
Here Try to change the format of your code in this pattern...
$class=$_GET['class']
switch($class) {
case 'dw':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [dw] > 0 order by credits asc");
break;
case 'bk':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [bk] > 0 order by credits asc");
break;
case 'fe':
$query = mssql_query("select * from [WebShop] where [category]='".secure($string)."' and [fe] > 0 order by credits asc");
break;
default:
code to be executed if n is different from all labels;
}
来源:https://stackoverflow.com/questions/29769831/multiple-if-in-if-with-get-url