Hướng dẫn count data from database in php - đếm dữ liệu từ cơ sở dữ liệu trong php

1

Mới! Lưu câu hỏi hoặc câu trả lời và sắp xếp nội dung yêu thích của bạn. Tìm hiểu thêm.
Learn more.

Xin chào, tôi muốn hiển thị số lượng mục trong cơ sở dữ liệu. Sau đây là mã PHP:

$jobid = $_SESSION['SESS_MEMBER_JOB'];
$data = "SELECT * FROM attributes WHERE jobid = $jobid";
$attribid = mysql_query[$data] or die[mysql_error];

$count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
$database_count = mysql_query[$count];
//Declare the Array
$DuetiesDesc = array[];

print_r [$database_count];

Nhưng thay vì nhận được kết quả mong muốn, tôi nhận được:

ID tài nguyên #14

Xin vui lòng giúp đỡ

Đã hỏi ngày 16 tháng 5 năm 2013 lúc 6:19May 16, 2013 at 6:19

1

Nên đưa nó ra khỏi cách mà bạn không nên sử dụng mysql_* xem tại sao tôi không nên sử dụng các hàm mysql_* trong PHP?

Xem mã bên dưới ... Giải thích có trong các bình luận

$jobid = $_SESSION['SESS_MEMBER_JOB'];
// escape variables using mysql_real_escape_string
$data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];

$attrRes = mysql_query[$data] or die[mysql_error[]];

// I'm assuming you want all of the attributes return in this query in an array
$attributes = array[];
while[$row = mysql_fetch_assoc[$attrRes]]{
    $attributes[] = $row;
}

// Now if you want the count we have all of the records in the attributes array;

$numAttributes = count[$attributes];


// here is an example of how you can iterate through it..
print "

Found ".$numAttributes." attributes

"; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
".$cell."
";

Đã trả lời ngày 16 tháng 5 năm 2013 lúc 6:40May 16, 2013 at 6:40

OrangePillorangepillOrangepill

24.4K3 Huy hiệu vàng40 Huy hiệu bạc63 Huy hiệu Đồng3 gold badges40 silver badges63 bronze badges

Thử cái này


Đã trả lời ngày 16 tháng 5 năm 2013 lúc 6:30May 16, 2013 at 6:30

user2361114user2361114user2361114

1621 Huy hiệu vàng1 Huy hiệu bạc9 Huy hiệu đồng1 gold badge1 silver badge9 bronze badges

thử cái này

 $jobid = $_SESSION['SESS_MEMBER_JOB'];
 $data = "SELECT *FROM attributes WHERE jobid =$jobid";
 $attribid = mysql_query[$data] or die[mysql_error];

 $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
 $database_count = mysql_query[$count];
 //Declare the Array
 $DuetiesDesc = array[];
 $database_count=mysql_fetch_assoc[$database_count];
 echo $database_count['count[*]']; 

Đã trả lời ngày 16 tháng 5 năm 2013 lúc 6:55May 16, 2013 at 6:55

SandysandySandy

10713 Huy hiệu đồng13 bronze badges

Xem thảo luận

Cải thiện bài viết

Lưu bài viết

  • Đọc
  • Bàn luận
  • Xem thảo luận

    Cải thiện bài viết

    Lưu bài viết

    Đọc

    Bàn luận

    Requirements::

    • PHP là viết tắt của bộ tiền xử lý siêu văn bản. MySQL là ngôn ngữ truy vấn cơ sở dữ liệu được sử dụng để quản lý cơ sở dữ liệu.

    Trong bài viết này, chúng tôi sẽ thảo luận về cách lấy số lượng hàng trong một bảng cụ thể có trong cơ sở dữ liệu bằng PHP và MySQL. By using PHP and MySQL, one can perform database operations. We can get the total number of rows in a table by using the MySQL mysqli_num_rows[]function.

    Syntax:

    XAMPP

    Cách tiếp cận: Bằng cách sử dụng PHP và MySQL, người ta có thể thực hiện các hoạt động cơ sở dữ liệu. Chúng ta có thể nhận được tổng số hàng trong một bảng bằng cách sử dụng hàm mysql mysqli_num_rows [].mysqli_query[] function.

    mysqli_num_rows [kết quả];The following table has 5 rows.

    Kết quả là để chỉ định định danh tập kết quả được trả về bởi hàm mysqli_query [].

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }

    Ví dụ: Bảng sau có 5 hàng.The expected result is as follows.

    Total rows in this table : 5

    Để đếm số lượng hàng trong bảng xây dựng, đoạn mã sau được sử dụng.

    • Đầu ra: Kết quả dự kiến ​​là như sau.
    • Các bước cho cách tiếp cận:
    • Tạo một cơ sở dữ liệu có tên là cơ sở dữ liệu.
    • Tạo một bảng có tên tòa nhà bên trong cơ sở dữ liệu.

    Steps:

    • Chèn hồ sơ vào nó.

    Viết mã PHP để đếm hàng.

    • Bắt đầu máy chủ XAMPP.
    • Máy chủ XAMPP

    Tạo một cơ sở dữ liệu có tên cơ sở dữ liệu và tạo một bảng có tên tòa nhà bên trong cơ sở dữ liệu.

    • Tạo một bảng có tên tòa nhà bên trong cơ sở dữ liệu.

    Mã PHP:

    PHP

    1

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    1
    
    
    3

    Total rows in this table : 5
    4
    
    
    1
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    3
    
    
    3

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9
    
    
    5
    
    
    6
    
    
    7
    
    
    8$con
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    0
    
    
    0
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    2

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    4
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    5
    
    
    7
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    8

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    9
    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    0
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    0
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    4
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    8

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    4

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    5$con
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    8

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    8

    Đầu ra: Sau khi chạy tệp PHP trên trong localhost, kết quả sau đây đã đạt được. After running the above PHP file in localhost, the following result is achieved.

    Total rows in this table : 5

    Ví dụ 2: Trong ví dụ sau, chúng tôi đếm các hàng bảng bằng hàm MySQL Count []. Nó có một chức năng tổng hợp được sử dụng để đếm các hàng.In the following example, we count the table rows using MySQL count[] function. It’s an aggregate function used to count rows.

    Syntax::

    chọn Đếm [*] từ bảng;

    Xem xét bảng.

    Mã PHP:

    PHP

    1

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    1
    
    
    3

    Total rows in this table : 5
    4
    
    
    1
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    3
    
    
    3

    Total rows in this table : 5
    8
    
    
    1
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    5
    
    
    3

    Total rows in this table : 5
    2
    Total rows in this table : 5
    3
    
    
    1
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    7
    
    
    3

    Total rows in this table : 5
    7
    
    
    1
    Total rows in this table : 5
    9
    Total Rows is 8
    0
    Total rows in this table : 5
    0
    Total Rows is 8
    2

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9
    Total rows in this table : 5
    4
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    0
    Total rows in this table : 5
    8
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    0
    Total rows in this table : 5
    3
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    8

    
    
    0
    
    
    1 7
    
    
    1
    Total rows in this table : 5
    7 0
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    8

    $con0

    
    
    6$con2 $con3
    
    
    7
     $jobid = $_SESSION['SESS_MEMBER_JOB'];
     $data = "SELECT *FROM attributes WHERE jobid =$jobid";
     $attribid = mysql_query[$data] or die[mysql_error];
    
     $count = "SELECT count[*] FROM attributes WHERE jobid = $jobid";
     $database_count = mysql_query[$count];
     //Declare the Array
     $DuetiesDesc = array[];
     $database_count=mysql_fetch_assoc[$database_count];
     echo $database_count['count[*]']; 
    
    2

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9$con7 $con8$con9
    
    

    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    9$con7
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    06
    
    
    3

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    4

    Total rows in this table : 5
    7
    $jobid = $_SESSION['SESS_MEMBER_JOB'];
    // escape variables using mysql_real_escape_string
    $data = "SELECT * FROM attributes WHERE jobid =".mysql_real_escape_string[$jobid];
    
    $attrRes = mysql_query[$data] or die[mysql_error[]];
    
    // I'm assuming you want all of the attributes return in this query in an array
    $attributes = array[];
    while[$row = mysql_fetch_assoc[$attrRes]]{
        $attributes[] = $row;
    }
    
    // Now if you want the count we have all of the records in the attributes array;
    
    $numAttributes = count[$attributes];
    
    
    // here is an example of how you can iterate through it..
    print "

    Found ".$numAttributes." attributes

    "; print ""; foreach[$attributes as $row]{ print ""; foreach [$row as $cell]{ print ""; } print ""; } print "
    ".$cell."
    ";
    10

    $sql = "SELECT * from building";
    
    if [$result = mysqli_query[$con, $sql]] {
    
        // Return the number of rows in result set
        $rowcount = mysqli_num_rows[ $result ];
        
        // Display result
        printf["Total rows in this table :  %d\n", $rowcount];
     }
    8

    Output:

    Total Rows is 8

    Làm thế nào tôi có thể đếm tổng dữ liệu trong PHP?

    Chúng ta có thể nhận được tổng số hàng trong một bảng bằng cách sử dụng hàm mysql mysqli_num_rows [].Cú pháp: mysqli_num_rows [kết quả];Kết quả là để chỉ định định danh tập kết quả được trả về bởi hàm mysqli_query [].using the MySQL mysqli_num_rows[] function. Syntax: mysqli_num_rows[ result ]; The result is to specify the result set identifier returned by mysqli_query[] function.

    Làm thế nào để bạn đếm hồ sơ trong cơ sở dữ liệu?

    Những gì để biết..
    Tính toán số lượng bản ghi trong bảng: Nhập chọn Đếm [*] [ENTER] từ tên bảng ;.
    Xác định số lượng các giá trị duy nhất trong một cột: Loại chọn đếm [tên cột riêng biệt] [enter] từ tên bảng ;.

    Làm cách nào để đếm dữ liệu trong MySQL?

    Để tính tất cả các hàng trong bảng, cho dù chúng có chứa các giá trị null hay không, hãy sử dụng Count [*].Hình thức đó của hàm đếm [] về cơ bản trả về số lượng hàng trong một tập kết quả được trả về bởi một câu lệnh select.use COUNT[*]. That form of the COUNT[] function basically returns the number of rows in a result set returned by a SELECT statement.

    Làm thế nào nhận được các giá trị từ cơ sở dữ liệu trong PHP?

    Có hai cách để kết nối với cơ sở dữ liệu bằng PHP ...
    MySQLI định hướng đối tượng $ Conn-> truy vấn [$ truy vấn] ;.
    MySQLI Thủ tục MySQLI_Query [$ Conn, $ Query].
    PDO.$ STMT = $ Conn-> Chuẩn bị [$ Truy vấn];$ STMT-> EXECUTE [] ;.

    Bài Viết Liên Quan

    Chủ Đề