gpt4 book ai didi

php - 故障排除 "Warning: mysqli_result::fetch_array() expects parameter 1 to be long, object given"

转载 作者:可可西里 更新时间:2023-11-01 01:05:48 27 4
gpt4 key购买 nike

我收到的警告是:

Warning: mysqli_result::fetch_array() expects parameter 1 to be long, object given in...line 103.

我在第 103 行旁边注释了 while ($row = $result->fetch_array($result)) {

问题 2:我可以将其中的任何内容存储在包含文件中吗?

问题 3:对于 $query,我可以将这些 Buyer、Seller 中的任何一个存储在某个数组中吗?怎么办?

/* FETCH CONTACT INFORMATION */

$query = ("SELECT * FROM contacts WHERE contacttype IN ('Buyer','Seller','Buyer / Seller','Investor') AND leadstatus = 'New' ORDER BY date DESC");

$ID = $row ['ID'];
$firstname = $row ['firstname'];
$lastname = $row['lastname'];
$ID = $row['ID'];
$partner = $row['spousefirst'];
$phonecell = $row['phonecell'];
$email = $row['email'];
$date = $row['date'];
$contacttype = $row['contacttype'];
$agentassigned = $row['agentassigned'];
$leadstatus = $row['leadstatus'];

$result = $mysqli->query($query) or die ("Error: ".mysqli_error($mysqli));

echo'
<table class="results" id="results">
<thead>
<tr>
<th width="10"><input type="checkbox" name="checkAll" id="checkAll" class="checkall" value="check all"></th>
<th>NAME</td>
<th>PARTNER</td>
<th>PHONE</td>
<th>EMAIL</td>
<th>DATE</td>
<th>TYPE</td>
<th>AGENT</td>
<th>STATUS</td>
<th>NOTES</td>
<th>TASKS</td>
<th>&nbsp;</td>
</tr>
</thead>';

while ($row = $result->fetch_array($result)) { // THIS IS LINE 103

echo'
<tbody>
<tr>
<td width="10"><input type="checkbox" name="" id="" value="'.$ID.'"></td>
<td><a href="/backend/leads/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
<td><a href="/backend/leads/view/?ID='. $ID.'">'.$partner.'</a></td>
<td>'.$phonecell.'</td>
<td><a href="mailto:'. $email.'">'.$email.'</a></td>
<td>'.date("M jS, g:i A", strtotime($date)).'</td>
<td>'.$contacttype.'</td>
<td>'.$agentassigned.'</td>
<td>'.$leadstatus.'</td>
<td><a href="/backend/contacts/notes.php?ID='.$ID.'">View</a> +</td>
<td><a href="/backend/contacts/todo.php?ID='.$ID.'">View</a> +</td>
<td><a href="/backend/contacts/deletesuccess.php?ID='.$ID.'">D</a></td>
</tr>
</tbody>
</table>';

}
?>

最佳答案

在面向对象模式下,参数为fetch_array()指定获取类型 ( MYSQLI_ASSOC, MYSQLI_NUM ),并且不获取结果资源。

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

那么在你的循环中,我们假设你想使用来自 $row 的 key 而不是普通变量。从上方将变量赋值移动到循环中。

while ($row = $result->fetch_array(MYSQLI_ASSOC)) {

// Move these assignments into the loop so they are available to your
// echo statement when constructing your <tbody>
$ID = $row ['ID'];
$firstname = $row ['firstname'];
$lastname = $row['lastname'];
$partner = $row['spousefirst'];
$phonecell = $row['phonecell'];
$email = $row['email'];
$date = $row['date'];
$contacttype = $row['contacttype'];
$agentassigned = $row['agentassigned'];
$leadstatus = $row['leadstatus'];

echo'
<tbody>
<tr>
<td width="10"><input type="checkbox" name="" id="" value="'.$ID.'"></td>
<td><a href="/backend/leads/view/?ID='.$ID.'"><strong>'.$firstname.' '.$lastname.'</strong></a></td>
<td><a href="/backend/leads/view/?ID='. $ID.'">'.$partner.'</a></td>
<td>'.$phonecell.'</td>
<td><a href="mailto:'. $email.'">'.$email.'</a></td>
<td>'.date("M jS, g:i A", strtotime($date)).'</td>
<td>'.$contacttype.'</td>
<td>'.$agentassigned.'</td>
<td>'.$leadstatus.'</td>
<td><a href="/backend/contacts/notes.php?ID='.$ID.'">View</a> +</td>
<td><a href="/backend/contacts/todo.php?ID='.$ID.'">View</a> +</td>
<td><a href="/backend/contacts/deletesuccess.php?ID='.$ID.'">D</a></td>
</tr>
</tbody>
</table>';

}

编辑

关于你的其他几个问题...

我会说将其存储在包含文件中并没有太多好处。它的代码不多,如果您不打算在其他地方重用它,那么将它移出此文件不会有任何好处。

您的查询是静态的,没有使用任何 PHP 变量。因此,将它们存储在数组中也没有太大好处,这将需要在 PHP 中进行额外的工作才能转换为 SQL。

$options = array('Buyer','Seller','Buyer / Seller','Investor');
// Join them into a string and quote both ends of it.
// If this includes any user input, you must call `$mysqli->real_escape_string()` on _each_ of them.
// Since in this one instance it is static in your code though without variables, that isn't necessary here
$options = "'" . implode("','", $options) . "'";
$query = ("SELECT * FROM contacts WHERE contacttype IN ($options) AND leadstatus = 'New' ORDER BY date DESC");

关于php - 故障排除 "Warning: mysqli_result::fetch_array() expects parameter 1 to be long, object given",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11269269/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com