我在我的网站上制作了一个收藏夹功能,有人可以选择不同的项目,并将其保存为帐户中的收藏包。所有项目都保存在收藏夹中,并附有最喜欢的ID号。任何具有相同ID号的东西都在一起。这将保存在登录的客户下。
我正在尝试将此数组导入到PHP页面中,并以灯箱类型的外观图形显示这些项目,但在将它们组合在一起以正确显示它们时遇到了很多麻烦。
数组和php代码如下。该数组是从SQL查询生成的。数组[0]和[1]的项目需要组合在一起,以便我可以将每个图像显示在一起(图像实际上彼此重叠,使其看起来像一个包。
以下是该页面的链接,以便您了解:https://www.viva-cards.com/products/package-designer除非您登录,否则您将无法看到喜欢的功能
我基本上需要将相同的fav_seq ID组合在一起,但仍然能够区分itm_id,offer_id,inv_type_id,inv_thumbnail_url和offer_description,因为它们具有不同的图像并且与它们一起使用。我一直在撞到一堵砖墙。有没有办法在php页面上执行此操作,还是必须在SQL查询阶段执行此操作?我做错了什么?
以下是数组的代码:
[0] => Array
(
[entity_id] => 6
[itm_id] => 81
[fav_seq] => 1
[offer_id] => 1
[inv_css_tag] =>
[inv_type_id] => TYPE1
[inv_thumbnail_url] => image1-thumb.png
[offer_description] => Offer1
)
[1] => Array
(
[entity_id] => 6
[itm_id] => 198
[fav_seq] => 1
[offer_id] => 1
[inv_css_tag] => csstag
[inv_type_id] => TYPE2
[inv_thumbnail_url] => image2-thumb.jpg
[offer_description] => Offer2
)
[2] => Array
(
[entity_id] => 6
[itm_id] => 810
[fav_seq] => 2
[offer_id] => 4
[inv_css_tag] =>
[inv_type_id] => TYPE1
[inv_thumbnail_url] => image3-thumb.png
[offer_description] => Offer4
)
[3] => Array
(
[entity_id] => 6
[itm_id] => 98
[fav_seq] => 2
[offer_id] => 4
[inv_css_tag] => csstag
[inv_type_id] => TYPE2
[inv_thumbnail_url] => image4-thumb.jpg
[offer_description] => Offer4
)
这是我在php页面上用来生成显示的代码:
<div>
<h2>Favorites Saved</h2>
<?php
foreach($this->favorite_seq as $favorites){
if(empty($favorites['fav_seq'])){
// Nothing
?>
<?php }else {?>
<div id="favoritesThumbnailWrapper"> <!-- For TYPE1 -->
<div id="favoritesReferralThumb" class="cardPositionMiddle1">
<img src="<?= $this->inventory_url . $favorites['inv_thumbnail_url'];?>">
</div>
<div id="favoritesPresentationThumb"> <!-- For TYPE2 -->
<img src="<?= $this->inventory_url . $favorites['inv_thumbnail_url'];?>">
</div>
<div id="favoritesOffer"> <!-- For OFFER DESCRIPTION -->
<span><?= $favorites['offer_description'];?></span>
</div>
</div>
<?php
}
}
?>
答案 0 :(得分:0)
这可能有所帮助:
$favArray = array();
foreach($this->favorite_seq as $favorites){
if(!empty($favorites['fav_seq'])){
$favArray[$favorites['fav_seq']][] = $favorites;
}
}
print_r($favArray);
在$favArray
上迭代以显示记录。