我得到这个代码用于获取类别名称,并显示该类别中的项目:
<?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