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 "".$cell." ";
}
print " ";
}
print "
";
Đã 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
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 "".$cell." ";
}
print " ";
}
print "
";
1
3Total rows in this table : 54
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
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 "".$cell." ";
}
print " ";
}
print "
";
1
3Total rows in this table : 54
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 "".$cell." ";
}
print " ";
}
print "
";
3
3Total rows in this table : 58
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 "".$cell." ";
}
print " ";
}
print "
";
5
3Total rows in this table : 52
Total rows in this table : 53
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 "".$cell." ";
}
print " ";
}
print "
";
7
3Total rows in this table : 57
1Total rows in this table : 59
Total Rows is 80
Total rows in this table : 50
Total Rows is 82
$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 "".$cell." ";
}
print " ";
}
print "
";
9Total rows in this table : 54
$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[*]'];
0Total rows in this table : 58
$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[*]'];
0Total rows in this table : 53
$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 "".$cell." ";
}
print " ";
}
print "
";
8
0
1
7
1Total rows in this table : 57
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 "".$cell." ";
}
print " ";
}
print "
";
8$con
0
6$con
2 $con
3
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 "".$cell." ";
}
print " ";
}
print "
";
9$con
7 $con
8$con
9
$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 "".$cell." ";
}
print " ";
}
print "
";
9$con
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 "".$cell." ";
}
print " ";
}
print "
";
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 : 57
$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 "".$cell." ";
}
print " ";
}
print "
";
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