0

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 ?

4

1 回答 1

0

在这里尝试以这种模式更改代码的格式...

$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;
}
于 2015-04-21T10:46:00.997 回答