2016-03-06 73 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); 
相關問題