我有12列在下面的代碼,我想最好的,正確的和簡短的方式來選擇字段的用戶訂單(行)其中的字段不在表空/ 0。(所有字段爲INT和數目少於500)MYSQL從表的行中選擇多個字段/列非空
$conn = mysqli_connect("localhost", "root", "","table_name") or die("error");
$sql = "SELECT dqnt_91,deal_91,dqnt_92,deal_92,dqnt_93,deal_93,dqnt_94,deal_94,dqnt_95,deal_95,dqnt_96,deal_96 FROM table_name WHERE fid='$userid' AND COLUMNS ARE NOT EMPTY ";
$result = mysqli_query($conn, $sql);
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
$d_91 = $row['deal_91']; $d_92 = $row['deal_92']; $d_93 = $row['deal_93']; $d_94 = $row['deal_94']; $d_95 = $row['deal_95']; $d_96 = $row['deal_96'];
$qnt_91 = $row['dqnt_91']; $qnt_91 = $row['dqnt_92']; $qnt_91 = $row['dqnt_93']; $qnt_91 = $row['dqnt_94']; $qnt_91 = $row['dqnt_95']; $qnt_91 = $row['dqnt_96']; }
echo 'You have selected:'.$d_91.'for'.$deal_91.'<br>';
echo 'You have selected:'.$d_92.'for'.$deal_92.'<br>';
echo 'You have selected:'.$d_96.'for'.$deal_96.'<br>';
同樣,我想回聲出只有那些不是零(0)或空字段,並且如果它們零值,然後不顯示或回顯它們! 下面的代碼可以工作,但因爲我有12列,並可以添加更多,他們下面的代碼是不方便的。
SELECT [ all 12 x columns_name] FROM table_name WHERE table_name.column_name1!='' AND table_name.column_mame2!='' AND x another 10 times the last code ;
感謝,
根據輸入的內容,輸出可能是什麼樣子? – Drew
文本如下:您已選擇98作爲22,同時echo也是echo'您已選擇:'。$ dqnt_91.'for'。$ deal_91'。 – ninakind