警告:mysqli_num_rows()恰好需要1个参数,给定2个| mysql | mysqli [英] Warning: mysqli_num_rows() expects exactly 1 parameter, 2 given | mysql |mysqli

查看:65
本文介绍了警告:mysqli_num_rows()恰好需要1个参数,给定2个| mysql | mysqli的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在mysql_query中有这样的代码,工作正常. 但是我将所有代码移到mysqli_,如标题中一样抛出错误

mysql

$count = mysql_query("SELECT COUNT(*) FROM xxx limit 2") or die(mysql_error());
      $count = mysql_result($count,0);
      for($i=0; $i<$count;$i++){
        echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
      }

mysqli

   $count = mysqli_query($con,"SELECT COUNT(*) FROM xxx limit 2") or die(mysqli_error());
      $count = mysqli_num_rows($count,0);
      for($i=0; $i<$count;$i++){
        echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
      }

pls帮助.. 编辑 此代码用于

工作:在mysql_ < http://www.imagebam.com/image/830cf2469802470 /p>

不起作用:我已经做了mysqli_num_rows($ count); http://www.imagebam.com/image/a32c87469802459

用于对此进行计数的代码: http://www.imagebam.com/image/f8a0b9469803871看到红色

解决方案

mysqli_num_rows 甚至与 mysql_result .

在这种情况下,在mysqli中替换mysql_result的方法是获取整个行并仅使用第一个元素,例如;

$result = mysql_query("SELECT COUNT(*) FROM xxx limit 2") or die(mysql_error());
$row = mysqli_fetch_row($result);
$count = $row[0];

for($i=0; $i<$count;$i++){
    echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
}

i have code like this in mysql_query , works fine. but i moving all the code to mysqli_ its throw error like in the title

mysql

$count = mysql_query("SELECT COUNT(*) FROM xxx limit 2") or die(mysql_error());
      $count = mysql_result($count,0);
      for($i=0; $i<$count;$i++){
        echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
      }

mysqli

   $count = mysqli_query($con,"SELECT COUNT(*) FROM xxx limit 2") or die(mysqli_error());
      $count = mysqli_num_rows($count,0);
      for($i=0; $i<$count;$i++){
        echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
      }

pls help .. editt. this code for

work : http://www.imagebam.com/image/830cf2469802470 in mysql_

not working : i already did the mysqli_num_rows ($count); http://www.imagebam.com/image/a32c87469802459

this code for counting this : http://www.imagebam.com/image/f8a0b9469803871 see the red

解决方案

mysqli_num_rows does nothing even remotely similar to mysql_result.

The replacement for mysql_result in mysqli in this case would be to fetch the entire row and use the first element only, something like;

$result = mysql_query("SELECT COUNT(*) FROM xxx limit 2") or die(mysql_error());
$row = mysqli_fetch_row($result);
$count = $row[0];

for($i=0; $i<$count;$i++){
    echo '<li data-target="#transition-timer-carousel" data-slide-to="'.$i.'"'; if($i==0){ echo 'class="active"'; } echo '></li>';
}

这篇关于警告:mysqli_num_rows()恰好需要1个参数,给定2个| mysql | mysqli的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆