"菜单"有4个子菜单。按钮是饮料,主菜,开胃菜和甜点。当用户点击饮料时,他们将被引导到饮料,当他们转到其他子菜单按钮时也是如此。但是我想在用户点击"菜单"时显示所有菜单。按钮。我知道我必须使用"否则"但菜单根本不显示。
menu.php
<div class="products">
<?php
if (isset($_GET['id'])) {
//current URL of the Page. basket_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli->query("SELECT * FROM menu WHERE MenuTypeID = ".$_GET['id']);
$currency = '$';
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="basket_update.php">';
echo '<div class="product-thumb"><img src="'.$obj->MenuPicture.'" /></div>';
echo '<div class="product-content"><h3>'.$obj->MenuName.'</h3>';
echo '<div class="product-desc">'.$obj->MenuDescription.'</div>';
echo '<div class="product-info">';
echo 'Price: '.$currency.$obj->MenuPrice.' | ';
echo 'Qty <input type="text" name="menu_qty" value="1" size="1" />';
echo '<button class="add_to_basket">Add To Basket</button>';
echo '</div></div>';
echo '<input type="hidden" name="MenuID" value="'.$obj->MenuID.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
?>
<?php
}else{
$query2 = "SELECT * FROM Menu";
$result2 = mysql_query($query2);
}
?>
</div>
答案 0 :(得分:1)
试试这段代码。
<div class="products">
<?php
if (isset($_GET['id'])) {
$results = $mysqli->query("SELECT * FROM menu WHERE MenuTypeID = ".$_GET['id']);
}
else{
$results = $mysqli->query("SELECT * FROM menu");
}
//current URL of the Page. basket_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$currency = '$';
if ($results) {
//fetch results set as object and output HTML
while($obj = $results->fetch_object())
{
echo '<div class="product">';
echo '<form method="post" action="basket_update.php">';
echo '<div class="product-thumb"><img src="'.$obj->MenuPicture.'" /></div>';
echo '<div class="product-content"><h3>'.$obj->MenuName.'</h3>';
echo '<div class="product-desc">'.$obj->MenuDescription.'</div>';
echo '<div class="product-info">';
echo 'Price: '.$currency.$obj->MenuPrice.' | ';
echo 'Qty <input type="text" name="menu_qty" value="1" size="1" />';
echo '<button class="add_to_basket">Add To Basket</button>';
echo '</div></div>';
echo '<input type="hidden" name="MenuID" value="'.$obj->MenuID.'" />';
echo '<input type="hidden" name="type" value="add" />';
echo '<input type="hidden" name="return_url" value="'.$current_url.'" />';
echo '</form>';
echo '</div>';
}
}
?>