伙计们,我在表格中选择非空值时遇到问题
$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos = ".$losuj['test1']."
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']." order by rand() limit 1"));
$szansa = rand(1,100000);
我arleady尝试添加和(cos IS NOT NULL) 但这里不起作用的是我的完整代码
$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos = ".$losuj['test1']."
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']." and (cos IS NOT NULL) order by rand() limit 1"));
$szansa = rand(1,100000);
答案 0 :(得分:1)
您可以使用其他查询但不是标准:
SELECT *
FROM table
WHERE NOT (YourColumn <=> NULL);
您还应该使用大写“AND”
你也可以试试这个:
mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where cos IS NOT NULL AND (cos = ".$losuj['test1']. "
OR cos = ".$losuj['test2']. "
OR cos = ".$losuj['test3']. "
OR cos = ".$losuj['test4']. "
OR cos = ".$losuj['test5']. "
OR cos = ".$losuj['test6']. ") ORDER BY rand() LIMIT 1"));
答案 1 :(得分:0)
我担心问题出在括号中。这种修正应该有效(注意括号):
$tabelka = mysql_fetch_array(mysql_query("select * from ".$server_db.".paczka_przedmiot where (cos = ".$losuj['test1']."
or cos = ".$losuj['test2']."
or cos = ".$losuj['test3']."
or cos = ".$losuj['test4']."
or cos = ".$losuj['test5']."
or cos = ".$losuj['test6']." ) and (cos IS NOT NULL) order by rand() limit 1"));
$szansa = rand(1,100000);