0

私はオンライン メニュー注文システムに取り組んでおり、そのカテゴリに従ってデータをフィルター処理したいと考えていました。このコードで動作させようとしましたが、1 つのカテゴリしか表示されません。

**<li><?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?> Scotch/Bourbon</a></li>
<li><?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?> Brandy/Cognac</a></li>
<li><?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?> Vodka/Gin/Tequila/Apertifs/Liqueur</a></li><br>
<li><?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?> Beer/Softdrinks</a></li>
<li><?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?> Cocktails</a></li>**

^基本的にこれらはカテゴリであり、以下はそれらを表示する方法です。**

<?php
$category = $_GET['choice'];
$category = str_replace('%', ' ', $category);
$query = "SELECT * FROM product_drinks WHERE drinks_cat = '" . $category . "'";
$result = mysql_query($query);
$total_records = mysql_num_rows($result); // the number of records in your result set
$num_cols = 2; // the number of columns
$num_rows = ceil($total_records / $num_cols); // the number of rows
$num = 0; // don't change this value, this is the first number of each record inside a record set
echo "<table style= 'cellpadding:8 width:100'>\n";
// next the loop for the table rows
for ($rows = 0; $rows < $num_rows; $rows++) {
    echo "<tr bgcolor='black'>\n";
    // this is the loop for the table columns
    for ($cols = 0; $cols < $num_cols; $cols++) {
        if ($num < $total_records) { // show records if available (reduce by one because the first record is no. "0" (zero)
            // first create variables with the values of the current record
            $title = mysql_result($result, $num, "drinks_name");
            $clean_name = str_replace('_', ' ', $title);

            $price = mysql_result($result, $num, "drinks_shot");
            $price2 = mysql_result($result, $num, "drinks_bottle");
            $category = mysql_result($result, $num, "drinks_cat");
            $description = mysql_result($result, $num, "drinks_image");
            $title = str_replace(' ', '%', $title);
            echo "<td class='label'><a class='fancybox fancybox.ajax' href='food.php?drink=" . $title . "'>         
                    <img src='" . mysql_result($result, $num, 'drinks_image') . "'  class='masterTooltip' title= '" . $category . "'</a><br>";
            echo "<td style='width:50%' class='desc'><b>" . $clean_name . "</b><br> Shot:<font style='color:#0072bc'> Php " . $price . "</font><br> Bottle: <font style='color:#724c0e'>Php " . $price2 . "</font></td>\n";

        } else { // show an empty cell
            echo "<td>&nbsp;</td>\n";
        }
        $num++; // raise the number by one for the next record
    }
    echo "</tr>\n"; // there are no more cols in this row, close the table row tag
}
echo "</table>\n"; // end of the region = closing tag for the table element
?>
**

この壁をなんとか乗り越えたい。助けてください〜

4

1 に答える 1

0

まず最初に。

<?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?>
  1. コードの最初のチャンクでは、すべてのリンクに同じ変数を使用しています。ここで$categoryに異なる値を渡していますか。私はあなたがそうではないと信じています!したがって、すべてのリンクが同じURLを指しています。

  2. str_replace('%'、''、$ category)の代わりにurldecodeを使用する必要があります。(http://in2.php.net/urldecode)

  3. 読みやすく理解しやすいように、コードをインデントしてください:)

于 2013-01-26T17:21:15.097 に答える