Smarty MYSQL 数组关联 ID
我的 php 代码是这样的:
$products = mysql_query("SELECT p.* FROM products AS p "
."INNER JOIN products_cat_link AS cpl ON cpl.Product_ID = p.id "
."WHERE cpl.Category_ID = '$forcat' "
."ORDER BY p.id");
$products_row = array();
$products_images = array();
while($prow = mysql_fetch_assoc($products)) {
if (isset($prow['id'])) {
$product['info'] = $prow;
$images = mysql_query("SELECT * FROM products_images WHERE `Product_id` = '$prow[id]' ORDER BY id");
while($irow = mysql_fetch_assoc($images)) {
$images_result[] = $irow;
}
$product['images'] = $images_result;
$products_images[] = $product;
}
$product = '';
$images_result = '';
}
$smarty->assign('products_images',$products_images);
这使得一个像这样的数组
Array (
[info] => array (
[id] = 1
[name] = abc
)
[images] => array (
[Products_Image_Thumb] = 1a.jpg
[Products_Image_Big] = 1b.jpg
)
)
但是我无法使用 smarty 获取图像信息:
{foreach from=$products_images key=cols item=image name=images}
{if $cols % 4 == 0}<div>{/if}
<a href="images/products/big/{$image.images.Products_Image_Big}">
<img src="images/products/thumb/{$image.images.Products_Image_Thumb}" alt="Click to Enlarge" title="Click to Enlarge" width="87" height="65" style="margin:3px;" /></a>
{if $cols % 4 == 3}</div>{/if}
{if $smarty.foreach.images.last}</div>{/if}
{/foreach}
感谢您的帮助!
I have my php code like this:
$products = mysql_query("SELECT p.* FROM products AS p "
."INNER JOIN products_cat_link AS cpl ON cpl.Product_ID = p.id "
."WHERE cpl.Category_ID = '$forcat' "
."ORDER BY p.id");
$products_row = array();
$products_images = array();
while($prow = mysql_fetch_assoc($products)) {
if (isset($prow['id'])) {
$product['info'] = $prow;
$images = mysql_query("SELECT * FROM products_images WHERE `Product_id` = '$prow[id]' ORDER BY id");
while($irow = mysql_fetch_assoc($images)) {
$images_result[] = $irow;
}
$product['images'] = $images_result;
$products_images[] = $product;
}
$product = '';
$images_result = '';
}
$smarty->assign('products_images',$products_images);
That makes an array like this
Array (
[info] => array (
[id] = 1
[name] = abc
)
[images] => array (
[Products_Image_Thumb] = 1a.jpg
[Products_Image_Big] = 1b.jpg
)
)
But i cannot get the images information with smarty:
{foreach from=$products_images key=cols item=image name=images}
{if $cols % 4 == 0}<div>{/if}
<a href="images/products/big/{$image.images.Products_Image_Big}">
<img src="images/products/thumb/{$image.images.Products_Image_Thumb}" alt="Click to Enlarge" title="Click to Enlarge" width="87" height="65" style="margin:3px;" /></a>
{if $cols % 4 == 3}</div>{/if}
{if $smarty.foreach.images.last}</div>{/if}
{/foreach}
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
根据我之前的回答的评论,这应该可行。然而它还没有经过测试,而且我已经有一段时间没有使用 Smarty 了。
Based off the comment on my previous answer, this should work. However it is untested and I haven't used Smarty in a while.