PHP 8.3.4 Released!

mysql_fetch_row

(PHP 4, PHP 5)

mysql_fetch_rowObtém uma linha como um array numérico

Aviso

Esta extensão tornou-se defasada a partir do PHP 5.5.0 e foi removida no PHP 7.0.0. Em vez disso, as extensões MySQLi ou PDO_MySQL devem ser usadas. Veja também o guia MySQL: escolhendo uma API. Alternativas a esta função incluem:

Descrição

mysql_fetch_row(resource $result): array

Retorna um array numérico que corresponde a linha obtida e move o ponteiro interno dos dados adiante.

Parâmetros

result

O resource do resultado que está sendo avaliado. Este resultado vem de uma chamada a mysql_query().

Valor Retornado

Retorna um array numérico de strings que corresponde linha obtida, ou false se não houverem mais linhas.

mysql_fetch_row() obtém uma linha de dados do resultado associado ao identificador do resultado especificado. A linha é retornada como um array. Cada coluna do resultado é armazenado em um índice do array, começando no índice 0.

Exemplos

Exemplo #1 Obtendo uma linha com mysql_fetch_row()

<?php
$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
$row[0]; // 42
echo $row[1]; // the email value
?>

Notas

Nota: Esta função define campos NULL como o valor null do PHP.

Veja Também

add a note

User Contributed Notes 4 notes

up
-21
a at simongrant dot org
22 years ago
Maybe worth pointing out that all the fields returned by this (and other?) calls are returned with type string. This had me puzzled for quite some time.
up
-23
michael and then an at sign wassupy.com
20 years ago
to print an array, simply use print_r(array name)

like this:
$myrow = mysql_fetch_row($result);
echo "<pre>";
print_r($myrow);
echo "</pre>";

this will output the array in a readable form, with the index, too. Don't forget the 'pre' tags or the output will be on a single line.
up
-26
pepik at gmail dot cz
10 years ago
<?php
require 'prhlavicka.php';
pis_hlavicku('Vypis článků');

require_once
'db.php';
$kom = new server();
$sql=$kom->query("SELECT autor,nazev,obsah FROM `Clanky_Sadek`");
while (
$data = mysql_fetch_row($sql)){
ECHO
'<br />--AUTOR--<br />'.$data[0].'<br />__NÁZEV ČLÁNKU__<br />'.$data[1].'<br />..OBSAH ČLÁNKU..<br />'.$data[2]; }

include
'Paticka.html'; ?>
up
-39
larkitetto at gmail dot com
16 years ago
sry :) note now fixed:

<?php
$esi
=mysql_list_tables($db);$ris=mysql_fetch_row($esi);
//example: $db has >= 1 tabs
echo var_dump($ris);
//echoes only array(1). solution:
while($ris=mysql_fetch_row($esi)) echo $ris[0];
/*debug:
$ris=array("1st_tab"); ... $ris=array("n_tab");$ris=false;*/
while ($ris[]=mysql_fetch_row($esi));
//debug:$ris=array(array("1st_tab"), ... array("n_tab"));
echo $ris[n][0];//echo:"n_tab"
echo $ris[0][n];//echo:array | null
?>

hope it helps
To Top