[Php 4, Php 5]
mysql_fetch_array - lấy hàng kết quả như một mảng kết hợp, một mảng số hoặc cả hai — Fetch a result row as an associative array, a numeric array, or both
Sự mô tả
mysql_fetch_array [tài nguyên $result
, int $result_type
= mysql_both]: mảng[resource $result
, int $result_type
= MYSQL_BOTH]: array
Thông số
result
Tài nguyên kết quả đang được đánh giá. Kết quả này đến từ một cuộc gọi đến mysql_query [].resource that is being evaluated. This result comes from a call to mysql_query[].
result_type
Loại mảng được lấy. Đó là một hằng số và có thể lấy các giá trị sau: MYSQL_ASSOC
, MYSQL_NUM
và MYSQL_BOTH
.MYSQL_ASSOC
, MYSQL_NUM
, and
MYSQL_BOTH
.
Trả về giá trị
Trả về một mảng các chuỗi tương ứng với hàng được tìm nạp hoặc false
nếu không còn hàng nữa. Loại mảng trả về phụ thuộc vào cách xác định result_type
. Bằng cách sử dụng MYSQL_BOTH
[mặc định], bạn sẽ nhận được một mảng có cả chỉ số kết hợp và số. Sử dụng MYSQL_ASSOC
, bạn chỉ nhận được các chỉ số kết hợp [vì mysql_fetch_assoc [] hoạt động], sử dụng MYSQL_NUM
, bạn chỉ nhận được các chỉ số số [như mysql_fetch_row [] hoạt động].false
if there are no more rows. The type of returned array depends on how result_type
is defined. By using MYSQL_BOTH
[default], you'll get an array with both associative and number indices. Using MYSQL_ASSOC
, you only get associative
indices [as mysql_fetch_assoc[] works], using MYSQL_NUM
, you only get number indices [as mysql_fetch_row[] works].
Nếu hai hoặc nhiều cột của kết quả có cùng tên trường, cột cuối cùng sẽ được ưu tiên. Để truy cập [các] cột khác cùng tên, bạn phải sử dụng chỉ mục số của cột hoặc tạo bí danh cho cột. Đối với các cột bí danh, bạn không thể truy cập nội dung với tên cột gốc.
Ví dụ
Ví dụ #1 truy vấn với tên trường trùng lặp bí danh
SELECT table1.field AS foo, table2.field AS bar FROM table1, table2
Ví dụ #2 mysql_fetch_array [] với MYSQL_NUM
mysql_fetch_array[] with MYSQL_NUM
$result
4
$result
5
$result
6Ví dụ #3 mysql_fetch_array [] với MYSQL_ASSOC
mysql_fetch_array[] with MYSQL_ASSOC
$result
4
$result
5
$result_type
0Ví dụ #4 mysql_fetch_array [] với MYSQL_BOTH
mysql_fetch_array[] with MYSQL_BOTH
$result
4
$result
5
$result_type
4Ghi chú
Lưu ý: Hiệu suất: Performance
Một điều quan trọng cần lưu ý là việc sử dụng mysql_fetch_array [] không chậm hơn đáng kể so với sử dụng mysql_fetch_row [], trong khi nó cung cấp một giá trị bổ sung đáng kể.mysql_fetch_array[] is not significantly slower than using mysql_fetch_row[], while it provides a significant added value.
Lưu ý: Tên trường được trả về bởi hàm này là nhạy cảm trường hợp.: Field names returned by this function are case-sensitive.
Lưu ý: Hàm này đặt các trường NULL thành giá trị PHP
$result_type
5.: This function sets NULL fields to the PHP$result_type
5 value.
Xem thêm
- mysql_fetch_row [] - Nhận một hàng kết quả như một mảng được liệt kê
- mysql_fetch_assoc [] - lấy hàng kết quả như một mảng kết hợp
- mysql_data_seek [] - di chuyển con trỏ kết quả nội bộ
- mysql_query [] - Gửi truy vấn MySQL
Robjohnson tại Black-Hole Dot Com ¶ ¶
20 năm trước
$result_type
6
$result_type
7
$result_type
8
$result_type
9
result
0Kingisulgard ¶ ¶
13 năm trước
result
1
result
2
result
3
result
4
result
5
result
6
result
0Puzbie tại Facebookanswers dot co dot uk ¶ ¶
11 năm trước
result
8
Mehdi Dot Haresi tại Gmail Dot Com ¶ ¶
13 năm trước
result
9
result_type
0
result_type
1
result_type
2Puzbie tại Facebookanswers dot co dot uk ¶ ¶
11 năm trước
result_type
3
result_type
4
result_type
5
result_type
6Mehdi Dot Haresi tại Gmail Dot Com ¶ ¶
maileremi tại gmail dot com
result_type
7
result_type
8
result_type
9
MYSQL_ASSOC
0
result
0John tại skem9 dot com ¶ ¶
16 năm trước
MYSQL_ASSOC
2
Joey tại Clean Dot Q7 Dot Com ¶ ¶
11 năm trước
MYSQL_ASSOC
3
MYSQL_ASSOC
4
result
0Mehdi Dot Haresi tại Gmail Dot Com ¶ ¶
maileremi tại gmail dot com
MYSQL_ASSOC
6
MYSQL_ASSOC
7
MYSQL_ASSOC
8
MYSQL_ASSOC
9
MYSQL_NUM
0
MYSQL_NUM
1
result
0John tại skem9 dot com ¶ ¶
13 năm trước
MYSQL_NUM
3
MYSQL_NUM
4
result
0Puzbie tại Facebookanswers dot co dot uk ¶ ¶
11 năm trước
MYSQL_NUM
6
MYSQL_NUM
7
MYSQL_NUM
8
MYSQL_NUM
9
result
0Mehdi Dot Haresi tại Gmail Dot Com ¶ ¶
maileremi tại gmail dot com
MYSQL_BOTH
1
MYSQL_BOTH
2
MYSQL_BOTH
3
MYSQL_BOTH
4
result
0John tại skem9 dot com ¶ ¶
maileremi tại gmail dot com
MYSQL_BOTH
6
MYSQL_BOTH
7
MYSQL_BOTH
8
result
0John tại skem9 dot com ¶ ¶
16 năm trước
false
0
false
1
false
2
false
3
false
4
result
0Joey tại Clean Dot Q7 Dot Com ¶ ¶
18 năm trước
false
6
false
7
false
8
false
9
result_type
0
result_type
1
result
0Ẩn danh ¶ ¶
maileremi tại gmail dot com
result_type
3
result_type
4
result_type
5
result_type
6
result_type
7
result_type
8
result_type
9
$result
00
$result
01
$result
02
$result
03
$result
04
$result
05
$result
06
$result
07
$result
08
$result
09
result
0John tại skem9 dot com ¶ ¶
13 năm trước
$result
11
$result
12
result
0Puzbie tại Facebookanswers dot co dot uk ¶ ¶
18 năm trước
$result
14
$result
15
$result
16
$result
17
$result
18
$result
19
result
0Ẩn danh ¶ ¶
13 năm trước
$result
21
$result
22
$result
23
$result
24
$result
25
result
0Puzbie tại Facebookanswers dot co dot uk ¶ ¶
maileremi tại gmail dot com
$result
27
$result
28
$result
29
result
0John tại skem9 dot com ¶ ¶
20 năm trước
$result
31
$result
32
$result
33
$result
34
result
0Kingisulgard ¶ ¶
20 năm trước
$result
36
$result
37
result
0Kingisulgard ¶ ¶
20 năm trước
$result
39
$result
40
$result
41
$result
42
$result
43
result
0Kingisulgard ¶ ¶
maileremi tại gmail dot com
$result
45
$result
46
$result
47
$result
48
result
0John tại skem9 dot com ¶ ¶
11 năm trước
$result
50
$result
51
$result
52
$result
53
result
0Mehdi Dot Haresi tại Gmail Dot Com ¶ ¶
20 năm trước
$result
55
$result
56
result
0Kingisulgard ¶ ¶
maileremi tại gmail dot com
$result
58
$result
59
$result
60
result
0John tại skem9 dot com ¶ ¶
18 năm trước
$result
62
$result
63
$result
64
$result
65
$result
66
$result
67
$result
68
result
0MJM tại porter dot appstate dot edu ¶ ¶
20 năm trước
$result
70
$result
71
$result
72
$result
73
$result
74
$result
75
$result
76
$result
77
$result
78
$result
79
result
0scott_carney tại hotmail dot com ¶
10 năm trước
$result
81
Typer85 tại gmail dot com ¶
15 năm trước
$result
82
$result
83
$result
84
$result
85
$result
86
$result
87