2017-10-05 39 views
0

所以我試圖將我的數據庫中的所有行都回顯到一個文件中,問題在於它缺少大約2800行,無法找到它們。行數與打印的行數不同

我試圖把一個try-catch,獲取數據的同時進行手動的循環不同的方法槽的結果,移動與data_seek指針....

所以這裏是代碼

$sql = 'SELECT connectedProducts,id,price,masterprice,cardprice,name,url,fullImage,categoryid1,categoryid2,categoryid3,sku,connectedCategory,connectedPrice,uniqueID 
     FROM sku_new 
     where name !="" and stock="in stock" and price != "" and masterprice != "%No%" 
     and fullimage != "http:" AND price != "No disponible" 
     and masterprice !="No disponible" and cardprice != "No disponible"'; 
$result=mysqli_query($con,$sql); 


while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $row['sku']."\r\n"; 
} 

這將打印38854行數據。然而,當我這樣做:

$sql = 'SELECT connectedProducts,id,price,masterprice,cardprice,name,url,fullImage,categoryid1,categoryid2,categoryid3,sku,connectedCategory,connectedPrice,uniqueID 
     FROM sku_new 
     where name !="" and stock="in stock" and price != "" and masterprice != "%No%" 
     and fullimage != "http:" AND price != "No disponible" 
     and masterprice !="No disponible" and cardprice != "No disponible"'; 
$result=mysqli_query($con,$sql); 

$row_cnt = $result->num_rows; 
echo $row_cnt; 

我得到41695 ...所以我不知道發生了什麼行的其餘部分,他們似乎只是dissapear,我已經嘗試了不同的方法,試圖讓他們並沒有什麼似乎工作...但是,如果我直接在數據庫上的DB可視化器上查詢,我得到41695行顯示正確...我一直在這個問題上打破我的頭,它沒有任何意義..我是什麼做錯了?

=====編輯========= 如果我從修改查詢:

$sql = 'SELECT connectedProducts,id,price,masterprice,cardprice,name,url,fullImage,categoryid1,categoryid2,categoryid3,sku,connectedCategory,connectedPrice,uniqueID 
      FROM sku_new 
      where name !="" and stock="in stock" and price != "" and masterprice != "%No%" 
      and fullimage != "http:" AND price != "No disponible" 
      and masterprice !="No disponible" and cardprice != "No disponible"'; 

要:

$sql = 'SELECT id,price,masterprice,cardprice,name,url,fullImage,categoryid1,categoryid2,categoryid3,sku,connectedCategory,connectedPrice,uniqueID 
      FROM sku_new 
      where name !="" and stock="in stock" and price != "" and masterprice != "%No%" 
      and fullimage != "http:" AND price != "No disponible" 
      and masterprice !="No disponible" and cardprice != "No disponible"'; 

我得到的所有41695行! !這沒有任何意義,我不修改WHERE指令!

+1

他們沒有消失,它不符合標準。我敢打賭,如果你在循環中添加更多的行/列,你會看到你得到的。 –

+0

@ Fred-ii-看起來他在兩個查詢中都有相同的標準。 – Barmar

+0

@Barmar打賭他們只有匹配'$ row ['sku']'而不是其他人的記錄數量。 –

回答

1

我認爲$row['sku']可以爲空的某些記錄。試試這個代碼,然後檢查總數。

$i = 1; 
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { 
    echo $i." - ".$row['sku']."\r\n"; 
    $i++; 

} 
+0

我得到38854 - 2000351581089作爲最後輸出...不會讓我最後2k行或... 我編輯了問題發佈更新 – Javier