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 — Obtém uma linha como um array numérico
Esta extensão tornou-se obsoleta 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:
mode
como PDO::FETCH_NUM
$result
): arrayRetorna um array numérico que corresponde a linha obtida e move o ponteiro interno dos dados adiante.
result
O resource do resultado que está sendo avaliado. Este resultado vem de uma chamada a mysql_query().
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.
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
?>
Nota: Esta função define campos NULL como o valor
null
do 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