multiple if in if with get url

孤街浪徒 提交于 2019-12-12 02:25:01

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!