我正在根据数据库中的库存制作宣传册生成器。由于纸质宣传册的外观,显示的项目顺序与mysql_fetch_array的工作方式不匹配。每个用户选择的类别在2X2网格中保存四个项目。
Category 1 ---------Category 2
[1] [2] ---------[5] [6]
[3] [4] ---------[7] [8]
Category 3 ---------Category 4
[9] [10] ---------[13] [14]
[11] [12] ---------[15] [16]
我已经创建了一个基本表作为此模式中项目的占位符。这是我要检索项目的查询。
$query = "SELECT t1.*, image_path FROM flyer_item AS t1
LEFT JOIN product_images AS t2 ON t1.product_id = t2.product_id WHERE id_page = '".$id_page."'";
echo $query."<br>";
$result = mysql_query($query);
echo '<h3 class = "splitter">Items</h3>';
//-create while loop and loop through result set
//Due to the unique item arrangement patter, we fill
//an array with the fetched array results.
$iArray = array();
while($row=mysql_fetch_array($result))
{
$iArray[] = $row;
$square = $row['square'];
$item_name = $row['item_name'];
$sales_info = $row['sales_info'];
$link = $row['image_path'];
$sku_item_number = $row['sku_item_number'];
if (empty($link))
{
$link = '../imagen/no_imagen.gif';
}
}
一页最多可容纳24个项目,所有项目均遵循上述模式,以确保项目属于各自的类别。我正在考虑制作另一个名为Categories的数据库表,它将存储它的四个项目,但有没有办法可以使用第二个数组iArray存储指示项目应该去的位置的数字?
实际表格如下所示,以匹配原始文档。
<table width="100%" border="1" bordercolordark="#000000" bordercolorlight="#000000">
<tr>
<td> </td>
<td colspan="2" align="center"><?php echo $category1; ?></td>
<td> </td>
<td colspan="2" align="center"><?php echo $category2; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 1</td>
<td>Item 2</td>
<td> </td>
<td>Item 5</td>
<td>Item 6</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 3</td>
<td>Item 4</td>
<td> </td>
<td>Item 7</td>
<td>Item 8</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2" align="center"><?php echo $category3; ?></td>
<td> </td>
<td colspan="2" align="center"><?php echo $category4; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 9</td>
<td>Item 10</td>
<td> </td>
<td>Item 13</td>
<td>Item 14</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 11</td>
<td>Item 12</td>
<td> </td>
<td>Item 15</td>
<td>Item 16</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td colspan="2" align="center"><?php echo $category5; ?></td>
<td> </td>
<td colspan="2" align="center"><?php echo $category6; ?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 17</td>
<td>Item 18</td>
<td> </td>
<td>Item 21</td>
<td>Item 22</td>
<td> </td>
</tr>
<tr>
<td> </td>
<td>Item 19</td>
<td>Item 20</td>
<td> </td>
<td>Item 23</td>
<td>Item 24</td>
<td> </td>
</tr>
</table>