我得到這個代碼用於獲取類別名稱,並顯示該類別中的項目:
<?php
// This block grabs the whole list for viewing
$cat_list="";
$cat=$_POST['cat'];
$cat_sql="SELECT * FROM products,prod_cat,categories WHERE categories.id=prod_cat.cat_id AND products.id=prod_cat.prod_id AND categories.id=$cat";
$cat_query=mysql_query($cat_sql) or die(mysql_error());
$results=mysql_fetch_assoc($cat_query);
$cat_list= "$results[cat_name]";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>show</title>
</head>
<?php echo $cat_list; ?>
</html>
它給了我這個錯誤:
Notice: Undefined index: cat in show.php on line 12
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
我需要的僅僅是從$cat
變量(如show.php?cat=6
)中的類別中顯示cat_name
。
您需要'$ _GET ['cat']'不要發帖,最好只在以下情況下調用您的數據庫:a)您創建(轉義)您的$ cat變量,b)$ cat不爲空() – Najzero 2013-02-12 08:11:22
變量like show .php?cat = 6是獲取請求,嘗試使用$ _GET數組 – BattleBit 2013-02-12 08:12:26
使用$ _GET [「cat」]而不是$ _POST [「cat」]; – ripa 2013-02-12 08:13:58