如何才能使这种语法有效?我得到它与其中一个结果。但是我要
从3.(result1
,result2
,result3
)获取查询。
$sql = "SELECT modulid=1 FROM oppgave WHERE resultat resultat2 resultat3 is NULL ORDER BY RAND() LIMIT 1";
任何提示如何查询3?
答案 0 :(得分:1)
尝试以下:
如果要检查resultat,resultat2和resultat3是否为null,请使用以下查询:
SELECT moduleid
FROM oppgave
WHERE modulid=1 and (resultat is null or resultat2 is null or resultat3 is NULL)
ORDER BY RAND() LIMIT 1;
如果要检查所有resultat,resultat2和resultat3应为null,请使用以下查询:
SELECT moduleid
FROM oppgave
WHERE modulid=1 and (resultat is null and resultat2 is null and resultat3 is NULL)
ORDER BY RAND() LIMIT 1;
答案 1 :(得分:0)
像这样重写您的查询..
SELECT *
FROM oppgave
WHERE modulid=1
AND
coalesce(resultat, resultat2, resultat3) IS NULL
ORDER BY RAND() LIMIT 1;
继续这样......
$result = mysql_query($sql, $tilkobling);
echo "<br>";
while ($nextrow= mysql_fetch_array($result)){
echo "Besvarelse: <br>" . $nextrow['besvarelse']; "<br>Modulid: " . $nextrow['modulid'];
}
此mysql_*
)扩展程序自PHP 5.5.0
起已弃用,将来会被删除。相反,应使用MySQLi
或PDO_MySQL
扩展名的准备好的语句来抵御SQL注入攻击!