2012-05-20 71 views
0

你好,我正在檢查數據庫中是否有一行,但對於一些resson,它一直說有但不是。我有很多如果站在一邊,所以我認爲這是問題。Mysql row always = 1

<?php 
if (isset($_POST['A'])) { 
$item2= mysql_real_escape_string($_POST['A']); 
$item = strip_tags($item2); 

$pokemonchoice= mysql_real_escape_string($_POST['B']); 
$pokemonchoicee = strip_tags($pokemonchoice); 



?><?php 
if ($pokemonchoicee == "Add to pokemon 1") { 
    $pokemonchoicee = '1'; 
} 
if ($pokemonchoicee == "Add to pokemon 2") { 
    $pokemonchoicee = '2'; 
} 
if ($pokemonchoicee == "Add to pokemon 3") { 
    $pokemonchoicee = '3'; 
} 
if ($pokemonchoicee == "Add to pokemon 4") { 
    $pokemonchoicee = '4'; 
} 
if ($pokemonchoicee == "Add to pokemon 5") { 
    $pokemonchoicee = '5'; 
} 
if ($pokemonchoicee == "Add to pokemon 6") { 
    $pokemonchoicee = '6'; 
} 

?> 

<?php 


$query = "SELECT * FROM items WHERE item='".$item."' AND belongsto='".$_SESSION['username']."'"; 
if(mysql_num_rows($query)!=0) 
{ 
echo "You do not have this item"; 
} 
else 
{ 
echo "You have this item"; 
} 

?> 

<?php 
echo $pokemonchoicee ; 
echo $item ; 
} 

?> 

這使打印真正的位

<?php 


$query = "SELECT * FROM items WHERE item='".$item."' AND belongsto='".$_SESSION['username']."'"; 
if(mysql_num_rows($query)!=0) 
{ 
echo "You do not have this item"; 
} 
else 
{ 
echo "You have this item"; 
} 

?> 

我刪除所有行,但還是說你有這個項目

+0

仍然越來越沒有這個項目,當物品在那裏,,, – user1405062

+0

改變那條線當然會給你其他回聲消息。 – keyser

回答

3

mysql_num_rows()得到一個MySQL的結果類型的資源,mysql_num_rows

之前使用 $query = mysql_query($query)
+0

另外,你可以使用mysql_num_rows(mysql_query($ query)) –

+0

只需閱讀你的編輯,現在它的作品謝謝 – user1405062

+0

謝謝這個作品 – user1405062

0

您在if語句中有錯誤。如果返回的行數大於0,則表示正在打印「您確實需要而不是有此項目」。它應該是相反的方式,所以改變!=檢查或讓回聲切換地方