PHP 8.3.4 Released!

mysql_fetch_row

(PHP 4, PHP 5)

mysql_fetch_rowObtiene una fila de resultados como un array numérico

Advertencia

Esta extensión fue declarada obsoleta en PHP 5.5.0 y eliminada en PHP 7.0.0. En su lugar debería utilzarse las extensiones MySQLi o PDO_MySQL. Véase también la guía MySQL: elegir una API. Las alternativas a esta función son:

Descripción

mysql_fetch_row(resource $result): array

Devuelve un array numérico que corresponde a la fila recuperada y mueve el puntero de datos interno hacia delante.

Parámetros

result

El resultado resource que está siendo evaluado. Este resultado proviene de una llamada a mysql_query().

Valores devueltos

Devuelve un array numérico que corresponde a la fila recuperada, o false si no quedan más filas.

mysql_fetch_row() recupera una fila de datos del resultado asociado al identificador de resultados especificado. La fila es devuelta como un array. Cada columna del resultado es almacenada en un índice del array, empezando desde 0.

Ejemplos

Ejemplo #1 Recuperar una fila con mysql_fetch_row()

<?php
$resultado
= mysql_query("SELECT id, email FROM people WHERE id = '42'");
if (!
$resultado) {
echo
'No se pudo ejecutar la consulta: ' . mysql_error();
exit;
}
$fila = mysql_fetch_row($resultado);

echo
$fila[0]; // 42
echo $fila[1]; // el valor de email
?>

Notas

Nota: Esta función define campos NULOS al valor null de PHP.

Ver también

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