我正在尝试通过会话发送两个数组,然后将它们组合在一起以显示在一起,但没有显示。这是我的代码--->
<?php
session_start();
function tee($uid){
include 'connect.php';
$uid=$uid;
$parent=array();
$child=array();
$_SESSION["child"]=array();
$_SESSION["parent"]=array();
$sql="select id from relation2 where parentID=$uid";
$result=mysql_query($sql,$link);
while($row=mysql_fetch_assoc($result))
{
$parent[]=$uid;
$child[]=$row["id"];
$_SESSION["child"][]=$child;
$_SESSION["parent"][]=$parent;
tee($row["id"]);
}
}
tee(2);
foreach(array_combine($_SESSION["child"],$_SESSION["parent"]) as $child=>$parent)
{
echo $child.'----------->'.$parent;
echo '<br>';
}
?>
答案 0 :(得分:0)
我用自定义内容替换了查询输出,并且此代码对我有用
<?php
session_start();
function tee($uid){
include 'connect.php';
$parent=array();
$child=array();
$_SESSION["child"]=array();
$_SESSION["parent"]=array();
$sql="select id from relation2 where parentID=$uid";
$result=mysqli_query($sql,$link);
while($row=mysqli_fetch_assoc($result))
{
$_SESSION["child"][]=$row["id"];
$_SESSION["parent"][]=$uid;
}
tee(2);
foreach(array_combine($_SESSION["child"],$_SESSION["parent"]) as $child=>$parent)
{
echo $child.'----------->'.$parent;
echo '<br>';
}
?>
还要检查extract()函数
如果您通过用户输入传递了$uid
,请使用PDO