Reputation: 1
So I'm trying to echo all the rows from my DB to a file, the issue is that its missing around 2800 rows and they're nowhere to be found.
I've tried putting a try-catch, different methods of fetching the data and also making a manual for to loop trough the result and moving the pointer with data_seek....
So here is the code
$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";
}
This prints 38854 rows of data. However when I do :
$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;
I get 41695 ... So I dont know what happens to the rest of the rows, they just seem to dissapear, I've tried different methods to try and get them and nothing seems to work... however if I make a query on a DB visualizer directly on the DB I get 41695 rows displaying correctly... I've been breaking my head on this and it doesn't make sense.. What am I doing wrong?
===== EDIT========= If I modify the query from:
$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"';
To:
$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"';
I get all 41695 rows!!! this makes no sense, I'm not modifying the WHERE instruction!!
Upvotes: 0
Views: 39
Reputation: 445
I think $row['sku']
can be empty for some records. Try this code and then check total count.
$i = 1;
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) {
echo $i." - ".$row['sku']."\r\n";
$i++;
}
Upvotes: 1