duanhe6799 2014-03-12 13:54
浏览 8

查询帮助(Sql和PHP)

I have the following query:

$lsel_lijst = mysql_query("SELECT * FROM users WHERE (owner = $id AND extern = 0 ) OR ( extern = $id )");

This gives me a whole list of users where owner = $id or where extern = $id. After this query i want to specify a lot of groups out of this list. With level = 10, with level = 20, with level = 30 til 2000.
And put them in the right div box (box 10, box 20, box 30 etc.).

In stead of doing this:

$lsel_lijst = mysql_query("SELECT * FROM users WHERE level = 10 AND (owner = $id AND extern = 0 ) OR ( extern = $id )");
$lsel_lijst = mysql_query("SELECT * FROM users WHERE level = 20 AND (owner = $id AND extern = 0 ) OR ( extern = $id )");
$lsel_lijst = mysql_query("SELECT * FROM users WHERE level = 30 AND (owner = $id AND extern = 0 ) OR ( extern = $id )");

etc. My question is can i do the query one more time, like above, and select afterwards?

  • 写回答

5条回答 默认 最新

  • dongluo3331 2014-03-12 13:57
    关注

    Use an "in" clause:

    $lsel_lijst = mysql_query("SELECT * FROM users WHERE level in(10,20,30) AND (owner = $id AND extern = 0 ) OR ( extern = $id )");
    
    评论

报告相同问题?