我有一个查询来选择非空值的列,但它不起作用..请告诉我问题出在哪里。谢谢
$query= mysql_query("SELECT opt_one, opt_two, opt_three, opt_four, opt_five, opt_six FROM `table`
WHERE `opt_one` IS NOT NULL AND `opt_two` IS NOT NULL AND `opt_three` IS NOT NULL AND
`opt_four` IS NOT NULL AND `opt_five` IS NOT NULL AND `opt_six` IS NOT NULL AND q_id = '$id'")or die(mysql_error);
while($r3 = mysql_fetch_array($query))
{
$print = array($r3['opt_one'], $r3['opt_two'],
$r3['opt_three'],
$r3['opt_four'], $r3['opt_five'], $r3['opt_six']);
shuffle($print);
echo $print['0'];
echo '<br>';
echo $print['1'];
echo '<br>';
echo $print['2'];
echo '<br>';
echo $print['3'];
echo '<br>';
echo $print['4'];
echo '<br>';
echo $print['5'];
echo '<br>';
}
答案 0 :(得分:0)
我认为您的列中的值为空 NULL 。试试这个:
SELECT opt_one, opt_two, opt_three, opt_four, opt_five, opt_six
FROM `table`
WHERE (`opt_one` IS NOT NULL OR `opt_one` != '')
AND (`opt_two` IS NOT NULL OR `opt_two` != '')
AND (`opt_three` IS NOT NULL OR `opt_three` != '')
AND (`opt_four` IS NOT NULL OR `opt_four` != '')
AND (`opt_five` IS NOT NULL OR `opt_five` != '')
AND (`opt_six` IS NOT NULL OR `opt_six` != '')
AND q_id = '$id'
旁注: