dongmen1925 2014-07-22 23:49
浏览 99
已采纳

致命错误:未识别的方法mysqli:fetch_array()[复制]

This question already has an answer here:

I am writing a time clock program and I am running into an error that I can not seem to find in the code. After looking over the code, I do not find an error where it says there is one. I did a check on PHP Code Checker too and it did not find one. Here is the code that I am using. I have modified the sensitive information. What am I doing wrong and how can I fix it. I was following the example on the 3rd answer here: display data from SQL database into php/ html table

Here is the output:

Fatal error: Call to undefined method mysqli::fetch_array() in path to file on line 31

Punch ID Time Punch Type Group Department Notes and the code

<head>
    <title>View My Punches</title>
    <body bgcolor="#9966FF">
    <link rel="icon" type="image/ico" href="path to favicon"/>
</head>

<?php
error_reporting(E_ALL); ini_set('display_errors', 1);
define('DB_NAME', 'name');
define('DB_USER', 'user');
define('DB_PASSWORD', 'password');
define('DB_HOST', 'host');


$link = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

if ($link->connect_errno > 0){
    die('Could not connect: ' .connect_error());
}
$userid_value = $_POST['userid'];
$table = "tc_".$userid_value;
$checkusersql = "SELECT * FROM tc_users WHERE userid = '$userid_value'";
$usercheck = $link->query($checkusersql);
$punchessql = "SELECT * FROM $table";
$result = $link->query($punchessql);
if ($usercheck->num_rows == 0) {
    echo "Sorry, " . $userid_value . " is not a valid user ID. Please try again.";
}else {
    echo "<table>";
    echo "<tr><td>Punch ID</td><td>Time</td><td>Punch Type</td><td>Group</td><td>Department</td><td>Notes</td></tr>";
    while ($row = $link->fetch_array($result))
    {
        echo "<tr><td>" . $row['id'] . "</td><td>" . $row['time'] . "</td></tr>" . $row['punchtype'] . "</td><td>" . $row['groupname'] . "</td><td>" . $row['dept'] . "</td><td>" . $row['notes'] . "</td><td>";
    }
    echo "</table>";
}

?>
</div>
  • 写回答

2条回答 默认 最新

  • dtihe8614 2014-07-22 23:58
    关注

    Instead of $link->fetch_array($result) use $result->fetch_array()

    Valid optional mysqli_result::fetch_array() parameters are MYSQLI_ASSOC, MYSQLI_NUM or MYSQLI_BOTH (default) to determine if the values array should return in associative or numeric format.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 对于squad数据集的基于bert模型的微调
  • ¥15 为什么我运行这个网络会出现以下报错?CRNN神经网络
  • ¥20 steam下载游戏占用内存
  • ¥15 CST保存项目时失败
  • ¥15 树莓派5怎么用camera module 3啊
  • ¥20 java在应用程序里获取不到扬声器设备
  • ¥15 echarts动画效果的问题,请帮我添加一个动画。不要机器人回答。
  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事: