0

I'm working on an online menu ordering system and I wanted to filter the data according to its category. I've tried to make it work with this code but it's only displaying one category.

**<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>**

^ basically these are the categories and below is how display them. **

<?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
?>
**

I wish I could get over this wall. Please help~

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • 1
    [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://www.brightmeup.info/article.php?a_id=2). – NullPoiиteя Jan 26 '13 at 17:49

1 Answers1

0

First things first.

<?php echo "<a href='clubmarumenu.php?choice=".$category."'>"?>
  1. In the first chunk of code, you are using the same variable for all the links. Are you passing different values for $category here. I believe you are not! and hence all the links are pointing to the same url.

  2. You should use urldecode instead of str_replace('%', ' ', $category). (http://in2.php.net/urldecode)

  3. Please indent your code so that it can be read and understood easily :)

Jaspal Singh
  • 1,210
  • 1
  • 12
  • 17