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 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 MATLAB中streamslice问题
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 51单片机中C语言怎么做到下面类似的功能的函数(相关搜索:c语言)
  • ¥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的三轴机械手程序