0

ページに商品のリストを印刷しようとしています。これは今のところケーキです。しかし、私のアイテムのいくつかは名前を共有していますが、異なる属性を持っています。例は次のようになります...:

product:

keyboard
keyboard

size:

25 inches
23 inches

color:

red
blue

私のテーブルは次のようになります:id、product、size、colorなど...

したがって、クエリと印刷を行っている.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つのend divタグ(したがって、すべてのhtml noooを壊します!!)

多分ループする方法はありますか?または、ある種の条件付きロジックを使用して、すべての製品が共有する製品名に対して1回、ループしてすべての異なる属性を出力し、各属性が終了したら、終了HTMLを含めて印刷しますか?

したがって、6つの製品があり、半分が「keyboard」という名前で、残りの半分が「shoes」という名前の場合、TABLE製品名を出力できます。すべての属性のKEYBOARDテーブルすべての属性のKEYBOARDテーブルend TABLE

TABLE製品名:すべての属性のSHOESテーブルすべての属性の終了テーブル終了テーブル

そうすれば、すべての属性のスタイルを設定できます。これが正しく説明されていない場合は本当に申し訳ありませんが、私はまだ学んでいます。どんな助けでも大歓迎です!


私の問題を理解する必要がないかもしれない余分なものは、私が印刷しているテーブルの例であり、属性の印刷方法が問題である理由です。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>

この問題を見てくださった方、ありがとうございました!

4

1 に答える 1

1

名前による照合を停止しますが、セレクターとしてskuを使用し始めます。そうすれば、キーボードの数に関係なく、常に気を配ることができます。一般名の代わりにSKUを渡すようにページを設定します。

それ以外の場合は、信頼できる結果を得るには、寸法、重量、色、価格などの基準をwhereステートメントに追加する必要があります。

- アップデート -

例。

page.php?product_type =keyboard

<?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";
?>
于 2012-06-13T21:53:02.047 に答える