PHPで電子商取引サイトを作成する方法についてのチュートリアルに続きます。isset関数を使用する必要があるときは、正確にissetとGET関数を使用することができます
だから、最初、私はこのコードを使用して、サイドバー上のすべての製品ブランドを表示:
function getBrands(){
global $con;
$get_brands = "select * from brands";
$run_brands = mysqli_query($con, $get_brands);
while ($row_brands=mysqli_fetch_array($run_brands)){
$brand_id = $row_brands['brand_id'];
$brand_name = $row_brands['brand_name'];
echo "<li><a href='index.php?brand=$brand_id'>$brand_name</a></li>";
}
}
そして、ブランドに基づいて、すべての製品を表示することです、このコードがある:
function get_brand_pro(){
if(isset($_GET['brand'])){
$brand_id = $_GET['brand'];
global $con;
$get_brand_pro = "select * from products where product_brand='$brand_id'";
$run_brand_pro = mysqli_query($con, $get_brand_pro);
$count_brands = mysqli_num_rows($run_brand_pro);
if($count_brands==0){
echo "<h3>No products associated with this brand where foundd</h3>";
}
while($row_brand_pro = mysqli_fetch_array($run_brand_pro)){
$product_id = $row_brand_pro['product_id'];
$product_cat = $row_brand_pro['product_cat'];
$product_brand = $row_brand_pro['product_brand'];
$product_title = $row_brand_pro['product_title'];
$product_price = $row_brand_pro['product_price'];
$product_image = $row_brand_pro['product_image'];
echo "
<div class='single_product'>
<h3 class='product_title'>$product_title</h3>
<img src='admin-area/product_images/$product_image' alt='product image' width='250' height='250' />
<p class='product_price'>$ $product_price</p>
<div class='single_links'>
<a href='details.php?product_id=$product_id' class='details'>Details</a>
<a href='index.php?product_id=$product_id' class='add_cart'><button>Add to Cart</button></a>
</div>
</div>
";
}
}
}
から私の理解、ボタンがクリックされた場合、同じセットの機能が同じ働きをしています。
なぜisset([$ _GET ['brands'])を選んでいるのですか? データベースにbrandという名前の属性がないことがわかります。
あなたはどこが間違っているのか教えてください。
[確定PHPのISSETへのガイド、空](http://kunststube.net/isset/) – deceze
'brands'がここに'エコー "
brand_id ... –