我使用PHP Recursive function
创建了动态菜单,它运行正常。
现在我正在为特定用户实现特定的菜单项。为此,我在登录表中添加了一个字段,并在该字段1,3,4,6,7,8,9,10
中存储了这样的数据。但我的问题是如果给数据静态它工作正常但如果我将菜单项变量传递给查询,它只显示第一项并给出implode无效参数传递警告。
为什么我收到此消息?请帮我。提前谢谢
//getting login table values
$query=mysqli_query($con,"select * from login");
$row=mysqli_fetch_array($query);
//storing values to array
$menuitems=explode(',',$row['field3']);
//print_r($menuitems);
//exit(0);
function submenu($parentid=0){
global $con;
global $menuitems;
//converting array into string
$menuitems=implode(',',$menuitems);
//passing the menuitems into sqlquery if i pass data like this i am
//getting A menu items and getting waning message
$sql=mysqli_query($con,"SELECT * FROM test WHERE refid=".$parentid. "AND
id IN ('$menuitems')");
{
$rowcount=mysqli_num_rows($sql);
if($rowcount>0){
echo '<ul>';
}
while($row=mysqli_fetch_array($sql,MYSQLI_ASSOC)){
if($row['refid']==0){
echo '<li class="limain">'.$row['name'];
submenu($row['id']);
echo '</li>';
} else {
if($row['userdefined']){
echo '<li class="lichild"><a href="'.$row['userdefined'].'">'.$row['name'].'</a>';
} else {
echo '<li class="lichild">'.$row['name'];
}
submenu($row['id']);
echo '</li>';
}
}
if($rowcount>0){
echo '</ul>';
}
}
}
//executing function
submenu();
?>