我在上一个(第三个)动态下拉列表中遇到问题 - 结果错误。
<?php
include('dbconfig.php');
$action = $_REQUEST['action'];
if ($action=='showAll')
{$id = "0";}
else $id=$_POST['id'];
switch($action)
{
case 'showAll';
$stmt=$DB_con->prepare('SELECT * FROM slist GROUP BY site');
$stmt->execute();
break;
case 'site';
$stmt=$DB_con->prepare('SELECT menu FROM slist WHERE site=:id GROUP BY menu ORDER BY menu');
$stmt->execute(array(':id'=>$id));
break;
case 'menu';
$stmt=$DB_con->prepare('SELECT categ FROM slist WHERE menu=:id GROUP BY categ ORDER BY categ');
$stmt->execute(array(':id'=>$id));
break;
case 'categ';
$stmt=$DB_con->prepare('SELECT links FROM slist WHERE categ=:id GROUP BY categ ORDER BY links');
$stmt->execute(array(':id'=>$id));
break;
default:
$stmt=$DB_con->prepare('SELECT * FROM slist GROUP BY site');
$stmt->execute();
break;
}
?>
SELECT links FROM slist WHERE categ=:id GROUP BY categ ORDER BY links
$action=="categ"
返回错误的结束值(从列表中的第一个结果中获取结果),因为查询应如下所示:SELECT links FROM slist WHERE menu=:id AND categ=:id GROUP BY categ ORDER BY links
。
如何将“menu”变量的值传递给此查询?
SQL表列名和表中的几条记录:
`id`, `site`, `menu`, `categ`, `links`
28, 'CoursesWeb.net', 'PHP-MySQL', 'Tutorials', 'http://coursesweb.net/php-mysql/tutorials_t'
34, 'CoursesWeb.net', 'JavaScript', 'Tutorials', 'http://coursesweb.net/javascript/tutorials_t'
46, 'CoursesWeb.net', 'Flash-AS3', 'Tutorials', 'http://coursesweb.net/flash/tutorials_t'