2016-03-19 19 views
2
public function checkIfItemLeft($itemNameSecond){ 
     $query = "SELECT itemLeft 
        FROM items 
        WHERE itemName = '$itemNameSecond' 
        AND itemLeft > 0 Limit 1"; 
     if(mysqli_query($this->db->getDb(), $query)) { 
      return true; 
     } 
     mysqli_close($this->db->getDb()); 
     return false; 
    } 

EĞER nasıl kontrol edersiniz?Mysqli SEÇ NEREDEN

+0

'itemLeft> 0' iyi görünüyor. Bunun nesi var? Hata? Paylaş. Herşeyi paylaş. – Rudie

+0

, false değerini döndürür. Ama benim veritabanı itemLeft 10 –

cevap

1

sorgu da sadece kısa bir alternatif düşünce

$query="SELECT CASE WHEN itemLeft>0 THEN 1 ELSE 0 END 
     FROM items 
     WHERE itemName = '$itemNameSecond'"; 
$result=mysqli_query($this->db->getDb(), $query); 
if ($result) { // the condition is necessary in case not record exists ... 
    $row = mysqli_fetch_row($result); 
    $largerthan0 = $row[0]; // will contain 1 if the value was >0 
} 
else { 
    $largerthan0 = 0; 
} 

gibi yapılabilir:

public function checkIfItemLeft($itemNameSecond){ 
$query="SELECT COUNT(*) FROM items 
     WHERE itemName = '$itemNameSecond' AND itemLeft>0"; 
$result=mysqli_query($this->db->getDb(), $query); 
$row = mysqli_fetch_row($result); 
return ($row[0]>0); 
} 
+0

TEŞEKKÜR EDERİZ. Thats çalıştı! –