dtbonklcs575884485 2015-03-14 16:08
浏览 97
已采纳

PHP警告:mysqli_fetch_assoc()需要1个参数,3中给出

I get this error, I tried going through other similar threads but it didn't help.

here is php

$host = "http://www.domain.com";
$hostname = "localhost";
$username = "aaa";
$password = "sss";
$userstable = "ddd";
$dbName = "fff";

if ($url != $host){
$con = mysqli_connect($hostname, $username, $password, $dbName);
//@mysqli_select_db("$dbName");
// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
$query = mysqli_fetch_row(mysqli_query($con, "SELECT * FROM $userstable where(url = '$url')"));

if ($query == false){
$hits = "1";
$query2 = "INSERT INTO $userstable (url,hits) VALUES('$url','$hits')";
}
else {
$hitquery =  "SELECT `hits` FROM $userstable where url = '$url'";
$result = mysqli_query($con, $hitquery);
$hits = mysqli_fetch_assoc($result, 0,  'hits');
//$hits = mysqli_result(mysqli_query("SELECT `hits` FROM $userstable where url = '$url'"), 0,  "hits");
$query2 = "UPDATE $userstable SET `hits` = hits+1 where url = '$url'";
}
mysqli_query($con, $query2);
}
if(!$url) {
$url =  "$host";
}

eror generate on line 157

$hits = mysqli_fetch_assoc($result, 0,  'hits');

How to fix this mysqli ?

please you're help.

  • 写回答

2条回答 默认 最新

  • doubo1871 2015-03-14 16:25
    关注

    Syntax mysqli_fetch_assoc is:

    array mysqli_fetch_assoc ( mysqli_result $result )
    

    Try (for PHP >=5.4):

    $hits = mysqli_fetch_assoc($result)['hits'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化