2013-12-09 90 views
0

如何通過php獲取數據庫中的行總數並顯示它?我使用COUNT(column_name)FROM(table_name)在phpmyadmin中完成了它,但在應用使用php時我感到困惑。對不起,我的愚蠢的問題獲取行數並顯示

回答

0

嘗試做這樣的事情:

<?php 
    $mysqli = new mysqli("localhost", "my_user", "my_password", "world"); 

    /* check connection */ 
    if (mysqli_connect_errno()) { 
     printf("Connect failed: %s\n", mysqli_connect_error()); 
     exit(); 
    } 

    if ($result = $mysqli->query("SELECT Code, Name FROM Country ORDER BY Name")) { 

     /* determine number of rows result set */ 
     $row_cnt = $result->num_rows; 

     printf("Result set has %d rows.\n", $row_cnt); 

     /* close result set */ 
     $result->close(); 
    } 

    /* close connection */ 
    $mysqli->close(); 
    ?> 
+0

感謝幫助 – JazliPa

0
<?php  
$sql = mysql_query("SELECT * FROM `table`") or die(mysql_error()); 

    echo mysql_num_rows($sql); 
?> 
+0

它的工作原理謝謝! – JazliPa