Warning: mysqli_num_rows() expects exactly 1 param

2019-03-07 00:13发布

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

标签: php mysql mysqli
4条回答
何必那么认真
2楼-- · 2019-03-07 00:44

this error throws because PHP function

 int mysqli_num_rows ( mysqli_result $result )

needs only one argument.

Here is http://php.net/manual/ru/mysqli-result.num-rows.php documentation

查看更多
\"骚年 ilove
3楼-- · 2019-03-07 00:51

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>';
}
查看更多
小情绪 Triste *
4楼-- · 2019-03-07 01:00

According to PHP Manual

you must change $count = mysqli_num_rows($count,0); into $count = mysqli_num_rows($count);

NOTE:Don't use mysql any more.This extension was deprecated in PHP 5.5.0

查看更多
欢心
5楼-- · 2019-03-07 01:07

correct way of doing is

$sql="SELECT COUNT(*) FROM xxx limit 2";

if ($result=mysqli_query($con,$sql))
  {
  // Return the number of rows in result set
  $rowcount=mysqli_num_rows($result);
  printf("Result set has %d rows.\n",$rowcount);
  // Free result set
  mysqli_free_result($result);
  }

mysqli_close($con);
查看更多
登录 后发表回答