2016-03-06 136 views
-1

我在mysql_query中有这样的代码,工作正常。 但我将所有的代码mysqli_它扔错误,如在标题警告:mysqli_num_rows()需要刚好1个参数,2给出| mysql | 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>'; 
     } 

请帮助.. editt。 此代码为

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

不工作:我已经做了mysqli_num_rows($计数); http://www.imagebam.com/image/a32c87469802459

此代码为计数此:http://www.imagebam.com/image/f8a0b9469803871看到红色

+0

它更好的方式来阅读手册,知道发生了什么功能! – 2016-03-06 07:52:46

+0

'COUNT'将返回一个包含行数的整数,'mysqli_num_rows'(如果使用正确的参数调用)将计算*返回的整数数量*(一),而不是行数。可能不是你想要的。 –

回答

0

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>'; 
} 
+0

男人谢谢你,因为它的工作,我忘了dat!我必须再学习一次!再一次谢谢你! –

0

根据PHP Manual

必须更改$count = mysqli_num_rows($count,0);$count = mysqli_num_rows($count);

注意:不要使用mysql任何more.This扩展已在PHP 5.5.0中弃用

+0

我alredy做dat请看链接mysql的工作http://www.imagebam.com/image/830cf2469802470,不工作mysqli http://www.imagebam.com/image/a32c87469802459 –

+0

你到底想要什么?与此查询? 'SELECT COUNT(*)FROM xxx limit 2' – 2016-03-06 08:03:08

+0

此计时器见链接http://www.imagebam.com/image/f8a0b9469803871 –

-1

做的正确的方法是

$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); 
相关问题