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.
(PHP 4, PHP 5)
mysql_fetch_row — Obtiene una fila de resultados como un array numérico
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:
$result
): arrayDevuelve un array numérico que corresponde a la fila recuperada y mueve el puntero de datos interno hacia delante.
result
El resultado resource que está siendo evaluado. Este resultado proviene de una llamada a mysql_query().
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.
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
?>
Nota: Esta función define campos NULOS al valor
null
de PHP.
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.
<?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'; ?>
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.
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