我正在學習關於如何在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函數的工作原理與單擊按鈕相同。
爲什麼選擇isset([$ _ GET ['brands']])? 因爲我看到數據庫中沒有名爲品牌的屬性。
希望你能糾正我錯在哪裏。
[權威指南PHP的isset和EMPTY(http://kunststube.net/isset/) – deceze
'brands'是在這裏'回聲 「
brand_id ...其 –