行数与打印的行不同

时间:2017-10-05 20:16:15

标签: php mysql mysqli

所以我试图将我的数据库中的所有行回显到一个文件,问题是它丢失了大约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 ......所以我不知道其他行会发生什么,它们似乎消失了,我尝试了不同的方法尝试获取它们但似乎没有任何工作......但是如果我直接在数据库上对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 :(得分:1)

对于某些记录,我认为$row['sku']可以为空。尝试此代码,然后检查总计数。

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

}