我在一个数据库表中有图像产品ID,在另一个表中有图像Source。这些都是订单。一个订单中可以有多个图像。我想把每张照片发给Pwinty。
因此,对于我需要制作的每张图片:
$photo = $pwinty->addPhoto($order, "$size", "$source", "$qty", "ShrinkToFit");
// I have not got to the size and qty variable yet
// Because of that I have this instead
$photo = $pwinty->addPhoto($order, "4x6", "$source", "1", "ShrinkToFit");
现在,因为它们在多个表格中,所以我有以下代码:(根本不会返回上面的照片数组。
// Get the customers pictures for this order
foreach ($db->query("SELECT * FROM order_products WHERE order_id=$order_id") as $row)
$picture_info[] = $row;
if (count($picture_info) > 0):
foreach ($picture_info as $row):
$product_id = $row['product_id'];
echo $product_id;
foreach ($db->query("SELECT * FROM products WHERE product_id=$product_id") as $row)
$picture_source[] = $row;
foreach ($picture_source as $row):
$source = $row['product_image'];
echo $source;
// add some photos
$photo = $pwinty->addPhoto($order, "4x6", "$source", "1", "ShrinkToFit");
endforeach;
endforeach;
endif;
它返回的是:
14138646283376c471632817da60f95964cb2d57dc46.png
Array
(
[id] => 7776
[address1] => 2002 E Blain
[address2] =>
[postalOrZipCode] => 68460
[country] => United States
[addressTownOrCity] => Belvidear
[recipientName] => Joe Dohn
[textOnReverse] => Photos by AlphaHQ
[stateOrCounty] => Kansas
[status] => NotYetSubmitted
[payment] =>
[paymentUrl] =>
[photos] => Array
(
)
[documents] => Array
(
)
[stickers] => Array
(
)
)
查看图像数组是如何为空的?我需要修理什么?
答案 0 :(得分:-1)
优化注意:最好从select语句列出你想要的内容,而不是说SELECT *。 SQL将执行得更快
您能告诉我们您从所有回声中获得的输出吗?
此外,当你将事物作为测试回应时,最好输入一些描述你所回应的内容的文本,这样即使它被设置为NULL,你也会看到文本,现在该变量是空的。
现在看来
foreach ($db->query("SELECT * FROM products WHERE product_id=$product_id") as $row)
实际上并没有获得任何行。
您可以做的简单测试是
echo "My row is " + $row + "\n";
因此,您可以看到实际获得的行数。