我正在尝试在页面上打印出产品列表。到目前为止,这是蛋糕..但是,我的一些项目共享名称,但具有不同的属性。示例如下:
product:
keyboard
keyboard
size:
25 inches
23 inches
color:
red
blue
我的表看起来像这样:ID、产品、尺寸、颜色等...
所以我正在做查询和打印的.php看起来像这样
<div id="accordion">
<?php
$letter = $_GET['letter'];
//echo "$id";
include("database.php");
$result = mysql_query("SELECT UPPER(product) AS upperName, PRODUCTS.* FROM PRODUCTS WHERE product LIKE '$letter%' ORDER BY UPPER(product) ");
$prodName = "";
while($row = mysql_fetch_array($result))
{
if ($row['upperName'] != $prodName)
{
print('<div style="background-color:#666; padding-bottom:25px; margin-bottom:25px;">');
print ("<h1>" . "$row[product]" . "</h1>");
}
print ("$row[ndc]" . "<br />");
print ("$row[size]" . "<br />");
print ("$row[strength]" . "<br />");
print ("$row[imprint]" . "<br />");
print ("$row[form]" . "<br />");
print ("$row[color]" . "<br />");
print('</div>');
$prodName = $row['upperName'];
}
mysql_close($linkID);
?>
</div>
我的问题来自尝试设置属性样式。
你看到那个/div 标签了吗?我想在手风琴中设置这些东西的样式,但是对于该手风琴中具有相同名称的每个产品,这些东西都会重复。因此,如果我在那里包含div,它会以相同的名称打印 3 次 3 个结束div 标签(因此破坏了我所有的 html 不!!
有没有办法循环? 或者使用某种条件逻辑来打印顶部的东西,一次是所有产品共享的产品名称,然后循环并打印所有不同的属性,然后当每个属性完成后,然后包含我的结束 html?
所以如果我有6个产品,一半被命名为"键盘",另一半被命名为"鞋子"我可以把它打印出来吗桌子产品名称:键盘我所有属性的表我所有属性的结束表结束表
桌子产品名称:鞋类我所有属性的表我所有属性的结束表结束表
这样我就可以设置所有属性的样式。如果这没有得到正确的解释,我真的很抱歉,我仍在学习。任何帮助不胜感激!
您可能不需要弄清楚我的问题的额外内容,只是我正在打印的表格的示例以及为什么属性打印方式是一个问题。 1-2-3-4-5-6-7-8-9 是属性的数据。
<table cellspacing="0" cellpadding="0" border="0" width="649">
<tr>
<td width="180" height="10" valign="top"></td><td width="36" height="10" valign="top"></td><td width="433" height="10" valign="top"></td>
</tr>
<tr>
<td width="180" valign="top"><img src="images/slide1.gif" width="180" height="200" border="0" /></td>
<td width="36" valign="top"></td>
<td width="433" valign="top"><table cellspacing="0" cellpadding="0" border="0" width="433">
<tr>
<td valign="top"><span class="in-table-head">Name:</span></td>
<td valign="top"><span class="in-table-name">$row[name]</span></td>
</tr>
<tr>
<td valign="top"><span class="in-table-head">Therapeutic Category:</span></td>
<td valign="top"><span class="in-table-name">$row[therapeutic]</span></td>
</tr>
<tr>
<td colspan="2" valign="top"><span class="in-table-providers">Information for Providers</span></td>
</tr>
</table></td>
</tr></table>
<table cellspacing="0" cellpadding="0" border="0" width="649">
<tr>
<td><span class="in-table-att">NDC#:</span></td>
<td><span class="in-table-att">Strength:</span></td>
<td><span class="in-table-att">Size:</span></td>
<td><span class="in-table-att">Imprint:</span></td>
<td><span class="in-table-att">Form:</span></td>
<td><span class="in-table-att">Color:</span></td>
<td><span class="in-table-att">Shape:</span></td>
<td><span class="in-table-att">Pack Size:</span></td>
<td><span class="in-table-att">Rating:</span></td>
</tr>
</table>
<table cellspacing="0" cellpadding="0" border="0" width="649">
<tr>
<td>1</td>
<td>2</td>
<td>3</td>
<td>4</td>
<td>5</td>
<td>6</td>
<td>7</td>
<td>8</td>
<td>9</td>
</tr>
</table>
再次感谢任何看到这个问题的人!
停止按名称匹配,但开始使用SKU作为选择器。 这样,无论您有多少键盘,您始终都能找到现场。将页面设置为传递 SKU 而不是通用名称。
否则,您需要在where语句中添加更多标准,例如尺寸,重量,颜色,价格等......以获得可靠的结果。
--更新--
举个例子。
页面.php?product_type=键盘
<?php
// set up database
$db = mysqli_connect("localhost", "user", "pass", "database_name");
// Just using mysql escape string, you should consider adding more securty checking to prevent injection
$producttype = mysql_real_escape_string($_GET['product_type']);
$result = $db->query("SELECT * FROM `products` WHERE `products`.`type`='$producttype'");
$features["width"][]
$features["height"][]
$features["color"][]
$features["whatever"][]
while ($row = $result->fetch_assoc())
{
$features["width"][] = $row["width"];
$features["height"][] = $row["height"];
$features["color"][] = $row["color"];
$features["whatever"][] = $row["whatever"];
}
// printing the features
echo "You have selected $producttype<BR>";
echo "The following widths can be selected<BR><UL>";
foreach($features["width"] as $width)
echo "<LI>$width</lI>";
echo "</UL><P>The following heights can be selected<BR><UL>";
foreach($features["heights"] as $height)
echo "<LI>$height</lI>";
echo "</UL><P>The following colors can be selected<BR><UL>";
foreach($features["colors"] as $color)
echo "<LI>$color</lI>";
echo "</UL><P>The following whatevers can be selected<BR><UL>";
foreach($features["whatevers"] as $whatevers)
echo "<LI>$whatevers</lI>";
echo "</UL>";
echo "have a nice day";
?>