我正在为我的合作伙伴计划处理datafeed脚本,并且真的认为我是“做它”,但是当我运行该脚本时,它只创建了28个产品中的7个的CSV文件。在测试之前,我让所有产品都符合查询的条件,所以他们都应该包括在内。我甚至删除了库存水平和价格条件。仍然只有28个中的7个被添加到来自一个类别的csv文件5和另一个类别的2个。第一类只有5种产品,所有这些产品都会退货。但是第二类中只有23个被返回。为什么我的MySQL查询只返回28条记录中的7条?
目标用于从查询中的类别中获取所有产品的特定数据并将它们转储到csv文件中。
这是我第一次尝试写一个更复杂的SQL查询(对于初学者来说)。
使用print_r我发现问题是我的查询。我以为我以前有这个工作。工作时间和现在的区别在于,我包括抓取分类和catparentid。但即使我删除这些添加,我仍然得到相同的结果。现在我想我可能以为它在我的更大的产品数据库上工作过,但也许它实际上并没有返回所有的产品,而是因为我认为它们有那么多。
完整的脚本很长,但我在下面创建了一个新脚本,只是为了查看查询是否抓取所有记录......事实并非如此。 :(
如果我运行一个查询,以检查未关联产品(即那些没有分类协会),所有产品均与类别相关联。
所有的产品具有图像&品牌联想,所以我不要“我不觉得是问题要么
即使我完全删除Where子句中,只有7个产品被抓住
我也直接跑在数据库内查询并得到了相同的事情:。
Showing rows 0 - 6 (7 total, Query took 0.0029 sec)
SELECT isc_products.productid, isc_products.prodcode, isc_products.prodname, isc_products.produrl, isc_products.prodcalculatedprice, isc_products.proddesc, isc_products.prodcurrentinv, isc_products.upc, isc_categories.categoryid, isc_categories.catparentid, isc_categories.catname, isc_product_images.imagefilestd, isc_product_images.imagefilethumb, isc_brands.brandname
FROM isc_products
INNER JOIN isc_categories ON isc_products.prodcatids = isc_categories.categoryid
INNER JOIN isc_product_images ON isc_products.productid = isc_product_images.imageprodid
INNER JOIN isc_brands ON isc_products.prodbrandid = isc_brands.brandid
WHERE isc_categories.categoryid =10
OR isc_categories.categoryid =12
数据中是否有可能导致此问题的特殊字符?
或者我不正确地使用内部连接?
<pre>
<?php
// Make a MySQL Connection
mysql_connect("localhost", "myusername", "mypassword") or die(mysql_error());
mysql_select_db("mydatabase") or die(mysql_error());
$result = mysql_query("SELECT isc_products.productid,
isc_products.prodcode,
isc_products.prodname,
isc_products.produrl,
isc_products.prodcalculatedprice,
isc_products.proddesc,
isc_products.prodcurrentinv,
isc_products.upc,
isc_categories.categoryid,
isc_categories.catparentid,
isc_categories.catname,
isc_product_images.imagefilestd,
isc_product_images.imagefilethumb,
isc_brands.brandname
FROM isc_products
INNER JOIN isc_categories
ON isc_products.prodcatids = isc_categories.categoryid
INNER JOIN isc_product_images
ON isc_products.productid = isc_product_images.imageprodid
INNER JOIN isc_brands
ON isc_products.prodbrandid = isc_brands.brandid
WHERE isc_categories.categoryid = 17
OR isc_categories.categoryid = 15
OR isc_categories.categoryid = 16
OR isc_categories.categoryid = 12
OR isc_categories.categoryid = 13
OR isc_categories.categoryid = 14
OR isc_categories.categoryid = 11
OR isc_categories.categoryid = 10
AND isc_products.prodcurrentinv > 1
AND isc_products.prodcalculatedprice > 1.00
ORDER BY isc_categories.catname
")
or die(mysql_error());
while($row = mysql_fetch_array($result)){
print_r ($row);
}
// end of file
echo '<br/>****** Script successfully run! ******';
?>
</pre>
任何想法,将不胜感激。 Dislcaimer如果你的第一个想法是“你为什么不......”是因为我没有或不知道它。 :)有一天,我的朋友......有一天我会。 hahahaha
谢谢!
需要查看您的数据或至少架构。 – 2012-04-06 15:53:57