PHP 7.3.18MySQL 5.7.30這是相關(guān)的代碼,它立即失敗,所以我很感激它被糾正。第一個“如果”沒問題,但問題出在第二個和第三個。$targetcatid2、$targetcatid3、$targetweight2、$targetweight3 已正確聲明。目的是如果產(chǎn)品屬于 Category2 而不是 Category3,則重量將變?yōu)?Weight2,反之亦然。$row2=mysqli_fetch_array($select2);if($row2['category_id']== $targetcatid){ $row['product_weight']= $targetweight;}if($row2['category_id']== $targetcatid2 && !== $targetcatid3){ $row['product_weight']= $targetweight2;}if($row2['category_id']== $targetcatid3 && !== $targetcatid2){ $row['product_weight']= $targetweight3;}我最近的努力是:如果($row2['category_id']== $targetcatid){ $row['product_weight']= $targetweight; }如果($row2['category_id']== $targetcatid2 && $row2['category_id']!== $targetcatid3){ $row['product_weight']= $targetweight2; }elseif($row2['category_id']== $targetcatid3 && $row2['category_id']!== $targetcatid2){ $row['product_weight']= $targetweight3; }elseif($row2['category_id']== $targetcatid2 && $row2['category_id']== $targetcatid3){ $row['product_weight']= $targetweight3; }我發(fā)現(xiàn)新條件不起作用,即使是單獨使用也是如此。但是不明白為什么:elseif($row2['category_id'] == $targetcatid2 && $row2['category_id'] == $targetcatid3){ $row['product_weight'] = $targetweight3; }
1 回答

HUX布斯
TA貢獻(xiàn)1876條經(jīng)驗 獲得超6個贊
您沒有正確理解 && 運算符。
而不是這個
if($row2['category_id']== $targetcatid2 && !== $targetcatid3){
您應(yīng)該分別比較條件。
if($row2['category_id']== $targetcatid2 && $row2['category_id'] !== $targetcatid3){
- 1 回答
- 0 關(guān)注
- 132 瀏覽
添加回答
舉報
0/150
提交
取消