Php 从数据库获取数据并创建多维数组
我想通过从数据库中获取数据来创建多维数组。创建由特定用户添加的播客的第二个数组,但它不会提供数据库中另一个活动用户的输出。Php 从数据库获取数据并创建多维数组,php,arrays,json,Php,Arrays,Json,我想通过从数据库中获取数据来创建多维数组。创建由特定用户添加的播客的第二个数组,但它不会提供数据库中另一个活动用户的输出。 这是我的密码: require $_SERVER['DOCUMENT_ROOT'].'/config/init.php'; require CLASS_PATH.'user.php'; require CLASS_PATH.'podcast.php'; $user = new User(); $podcast = new Podcast(); $userList =
这是我的密码:
require $_SERVER['DOCUMENT_ROOT'].'/config/init.php';
require CLASS_PATH.'user.php';
require CLASS_PATH.'podcast.php';
$user = new User();
$podcast = new Podcast();
$userList = $user->getAllUserName();
foreach ($userList as $users) {
$fullname = $users->first_name. ' '. $users->last_name;
$data = array(
'name' => $fullname
);
$podcastList = $podcast->getUserPodcast($fullname);
$data['podcast'] = $podcastList;
}
您需要建立一个数据列表。将数据创建为1项将停止将
播客
数据从全名
中分离出来
$userList = $user->getAllUserName();
$data = [];
foreach ($userList as $users) {
$fullname = $users->first_name. ' '. $users->last_name;
$data[] = array(
'name' => $fullname,
'podcast' => $podcast->getUserPodcast($fullname)
);
}
仅限使用播客的用户
$userList = $user->getAllUserName();
$data = [];
foreach ($userList as $users) {
$fullname = $users->first_name. ' '. $users->last_name;
$podcast = $podcast->getUserPodcast($fullname);
if ( !empty($podcast) ) {
$data[] = array(
'name' => $fullname,
'podcast' => $podcast
);
}
}
这里的实际问题是什么?播客是否提供其他用户的结果?或者你可以制作多个数组?你的意思是什么?是什么让你认为它提供了另一个用户的输出?向我们展示输出,并描述它的错误代码工作正常,但是,如果播客的字段没有用户,我们能做些什么吗?我们可以从数组中删除该用户吗?我已经用新版本更新了代码。想法是在添加用户之前检查播客。我假设它是空的,当没有播客时,您可能需要根据这个值调整测试。