doumowu7371 2013-12-11 22:38
浏览 22

我有阵列问题

So, I want to have table with users name, grades and subjects. Table will display only his grades. So I'm generating subject in foreach loop and reading grades depending on his id.

For subject I want to have an array which will contain infos about subject (teacher, classroom, etc.)

For now I have this array:

$subjects = array();
$getSubjects = mysqli_query($con, "SELECT * FROM predmeti");
while ($subject = mysqli_fetch_array($getSubjects)) {
    $subjects[]= array(
        $subject['subject_name'] => array(
            'id' => $subject['id'],
            'name' => $subject['name'],
            'teacher' => $subject['teacher'],
            'short_name' => $subject['short_name'],
            'classroom' => $subject['classroom']
        )
    );

I know this isn't right. I can't get data for each subject.

Could you please help me?

  • 写回答

1条回答 默认 最新

  • doufan3408 2013-12-11 22:42
    关注

    You're accessing the columns by name while mysqli_fetch_array() returns only an integer indexed array. Have you tried mysqli_fetch_assoc()?

    评论

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序