fetch_row()
PHP mysqli fetch_row() funksiyasi
Misol - obyektga yo‘naltirilgan uslub
Natijalar to‘plamidan qatorlarni oling:
<?php
$mysqli = new mysqli("localhost","my_user","my_password","my_db");
if ($mysqli -> connect_errno) {
echo "Failed to connect to MySQL: " . $mysqli -> connect_error;
exit();
}
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
if ($result = $mysqli -> query($sql)) {
while ($row = $result -> fetch_row()) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
$result -> free_result();
}
$mysqli -> close();
?>
Protsedural uslubdagi misolni sahifa pastida ko‘ring.
Ta’rif va qo‘llanilishi
fetch_row() / mysqli_fetch_row() funksiyasi natijalar to‘plamidan bitta qatorni oladi va uni sonli indeksli massiv sifatida qaytaradi.
Sintaksis
Obyektga yo‘naltirilgan uslub:
$mysqli_result -> fetch_row()
Protsedurali uslub:
mysqli_fetch_row(result)
Parametr qiymatlari
| Parametr | Tavsif |
|---|---|
| result | Majburiy. mysqli_query(), mysqli_store_result() yoki mysqli_use_result() qaytargan natijalar to‘plami identifikatorini belgilaydi |
Texnik tafsilotlar
| Qaytariladigan qiymat: | Olingan qatorga mos keladigan stringlar massivini qaytaradi. Natijalar to‘plamida boshqa qator qolmagan bo‘lsa, NULL |
|---|---|
| PHP versiyasi: | 5+ |
Misol - protsedural uslub
Natijalar to‘plamidan qatorlarni oling:
<?php
$con = mysqli_connect("localhost","my_user","my_password","my_db");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
exit();
}
$sql = "SELECT Lastname, Age FROM Persons ORDER BY Lastname";
if ($result = mysqli_query($con, $sql)) {
// Fetch one and one row
while ($row = mysqli_fetch_row($result)) {
printf ("%s (%s)\n", $row[0], $row[1]);
}
mysqli_free_result($result);
}
mysqli_close($con);
?>
❮ PHP MySQLi ma’lumotnomasi
W3Schools Pathfinder
Yutuqlaringizni kuzating – bu bepul!
