0

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

Rama Diansyah S
  • 37
  • 1
  • 1
  • 5
  • its better way to read manual , to know whats happening in functions ! –  Mar 06 '16 at 07:52
  • `COUNT` will return an integer with the number of rows, and `mysqli_num_rows` (if called with the correct parameters) will count *the number of integers returned* (one), not the number of rows. Probably not what you want. – Joachim Isaksson Mar 06 '16 at 08:01

4 Answers4

1

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

  • i alredy do dat pls see the link mysql work http://www.imagebam.com/image/830cf2469802470 , not work mysqli http://www.imagebam.com/image/a32c87469802459 – Rama Diansyah S Mar 06 '16 at 07:59
  • what you exactly want? with this query ? `SELECT COUNT(*) FROM xxx limit 2` –  Mar 06 '16 at 08:03
  • Try to edit your question , don't put too much link ! –  Mar 06 '16 at 08:11
  • @RamaDiansyahS if you have image , or other things that you think that can help to make better answer , try to add them into your question . –  Mar 06 '16 at 08:17
0

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

DicBrus
  • 1,291
  • 9
  • 9
-1

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>';
}
Joachim Isaksson
  • 176,943
  • 25
  • 281
  • 294
-2

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);