0

我正在开发一个在线菜单订购系统,我想根据其类别过滤数据。我试图让它与这段代码一起工作,但它只显示一个类别。

**<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. 您应该使用 urldecode 而不是 str_replace('%', ' ', $category)。(http://in2.php.net/urldecode)

  3. 请缩进您的代码,以便可以轻松阅读和理解:)

于 2013-01-26T17:21:15.097 回答