Hướng dẫn how to fetch single value from database in php - làm thế nào để tìm nạp một giá trị từ cơ sở dữ liệu trong php

6

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.

Làm cách nào để lấy chỉ một giá trị từ cơ sở dữ liệu bằng PHP? Tôi đã thử tìm kiếm gần như ở khắp mọi nơi nhưng dường như không tìm thấy giải pháp cho những điều này, ví dụ: cho những gì tôi đang cố gắng làm là
I tried searching almost everywhere but don't seem to find solution for these e.g., for what I am trying to do is

"SELECT name FROM TABLE
WHERE UNIQUE_ID=Some unique ID"

Hướng dẫn how to fetch single value from database in php - làm thế nào để tìm nạp một giá trị từ cơ sở dữ liệu trong php

Hỏi ngày 5 tháng 10 năm 2010 lúc 18:28Oct 5, 2010 at 18:28

3

Làm thế nào về mã PHP sau:

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];

Tôi hy vọng nó cho tên mong muốn của bạn.

Các bước: 1.) Chuẩn bị câu lệnh SQL. 2.) Truy vấn DB và lưu trữ kết quả trong một biến 3.) Tìm nạp hàng kết quả đầu tiên trong biến tiếp theo 4.) In cột Desire
1.) Prepare SQL Statement.
2.) Query db and store the resultset in a variable
3.) fetch the first row of resultset in next variable
4.) print the desire column

Đã trả lời ngày 5 tháng 10 năm 2010 lúc 18:32Oct 5, 2010 at 18:32

Hướng dẫn how to fetch single value from database in php - làm thế nào để tìm nạp một giá trị từ cơ sở dữ liệu trong php

KoolkabinkoolkabinKoolKabin

16.6K35 Huy hiệu vàng105 Huy hiệu bạc145 Huy hiệu Đồng35 gold badges105 silver badges145 bronze badges

Đây là ý tưởng cơ bản từ đầu đến cuối:


Đã trả lời ngày 5 tháng 10 năm 2010 lúc 18:34Oct 5, 2010 at 18:34

Stevendesustevendesustevendesu

15K21 Huy hiệu vàng97 Huy hiệu bạc176 Huy hiệu đồng21 gold badges97 silver badges176 bronze badges

Bạn có thể tìm nạp một giá trị từ bảng bằng truy vấn này:

"SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID limit 1"

Lưu ý việc sử dụng giới hạn 1 trong truy vấn. Tôi hy vọng nó sẽ giúp !!limit 1 in the query. I hope it helps!!

Đã trả lời ngày 5 tháng 10 năm 2010 lúc 18:38Oct 5, 2010 at 18:38

Hướng dẫn how to fetch single value from database in php - làm thế nào để tìm nạp một giá trị từ cơ sở dữ liệu trong php

$conn = new mysqli($servername, $username, $password, $dbname);
$sql = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo $row["name"]."
"; } } else { echo "0 results"; } $conn->close();

Đã trả lời ngày 13 tháng 5 năm 2018 lúc 4:19May 13, 2018 at 4:19

(Php 4, Php 5)

mysql_fetch_row - Nhận một hàng kết quả như một mảng được liệt kêGet a result row as an enumerated array

Sự mô tả

mysql_fetch_row (tài nguyên $result): mảng(resource $result): 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().

Trả về giá trị

Trả về một mảng số của các chuỗi tương ứng với hàng được tìm nạp hoặc false nếu không có hàng.false if there are no more rows.

mysql_fetch_row () lấy một hàng dữ liệu từ kết quả được liên kết với định danh kết quả được chỉ định. Hàng được trả lại dưới dạng một mảng. Mỗi cột kết quả được lưu trữ trong một phần bù mảng, bắt đầu ở độ lệch 0. fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Ví dụ

Ví dụ #1 Tìm nạp một hàng với mysql_fetch_row ()mysql_fetch_row()

$result mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
    echo 
'Could not run query: ' mysql_error();
    exit;
}
$row mysql_fetch_row($result);

echo

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
0

Ghi chú

Lưu ý: Hàm này đặt các trường NULL thành giá trị PHP

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
1.: This function sets NULL fields to the PHP
$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
1
value.

Xem thêm

  • 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
  • mysql_fetch_assoc () - lấy hàng kết quả như một mảng kết hợp
  • mysql_fetch_object () - tìm nạp một hàng kết quả như một đối tượng
  • mysql_data_seek () - di chuyển con trỏ kết quả nội bộ
  • mysql_fetch_lengths () - Nhận độ dài của mỗi đầu ra trong một kết quả
  • mysql_result () - Nhận dữ liệu kết quả

Michael và sau đó là một dấu hiệu Wassupy.com

19 năm trước

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
2

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
3

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
4

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
5

A tại simongrant dot org ¶

20 năm trước

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
6

Pepik tại gmail dot cz ¶

9 năm trước

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
7

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
8

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
9

Larkitetto tại Gmail Dot Com ¶

14 năm trước


0


1

$strSQL = "SELECT name FROM TABLE WHERE UNIQUE_ID=Some unique ID";
$result = mysql_query($strSQL) or die('SQL Error :: '.mysql_error());
$row = mysql_fetch_assoc($result);
echo $row['name'];
5

Làm thế nào để có được một giá trị duy nhất từ ​​cơ sở dữ liệu bằng PHP?

$ servername = "localhost" ;.
$ username = "Tên người dùng" ;.
$ password = "Mật khẩu" ;.
$ dbname = "mydb" ;.
// Tạo kết nối ..
$ Conn = new mysqli ($ servername, $ username, $ password, $ dbname) ;.
// Kiểm tra kết nối..

Làm thế nào tìm nạp dữ liệu từ dữ liệu trong PHP?

Trong các hoạt động đọc, chúng tôi sẽ chỉ sử dụng các truy vấn để tìm nạp dữ liệu từ cơ sở dữ liệu ...
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 () ;.

Làm thế nào để lấy dữ liệu từ hàng trong PHP?

mysql_fetch_row () lấy một hàng dữ liệu từ kết quả được liên kết với định danh kết quả được chỉ định.Hàng được trả lại dưới dạng một mảng.Mỗi cột kết quả được lưu trữ trong một phần bù mảng, bắt đầu ở độ lệch 0. fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Làm cách nào để xem chi tiết của một bản ghi trong cơ sở dữ liệu MySQL bằng PHP?

$ link = mysql_connect ('localhost', 'root', 'yourPassword') mysql_select_db ('database_name', $ link);$ SQL = 'Chọn ID từ giới hạn trò chơi 1';$ result = mysql_query ($ sql, $ link) hoặc die (mysql_error ());$ row = mysql_fetch_assoc ($ result);print_r ($ hàng);