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 — Retourne une ligne de résultat MySQL sous la forme d'un tableau
Cette extension était obsolète en PHP 5.5.0, et a été supprimée en PHP 7.0.0. À la place, vous pouvez utiliser l'extension MySQLi ou l'extension PDO_MySQL. Voir aussi MySQL : choisir une API du guide. Alternatives à cette fonction :
$result
): array
mysql_fetch_row() retourne un tableau
indexé numériquement, qui correspond à la prochaine ligne
du résultat MySQL result
et
déplace le pointeur interne de données d'un cran.
result
La ressource de résultat qui vient d'être évaluée. Ce résultat vient de l'appel à la fonction mysql_query().
Retourne un tableau numérique de chaînes qui correspond à la ligne récupérée, ou
false
s'il n'y a plus de lignes.
mysql_fetch_row() va rechercher une ligne dans le
résultat associé à l'identifiant de résultat
spécifié. La ligne est retournée sous la forme d'un
tableau. Chaque colonne est enregistrée sous la forme d'un tableau
commençant à la position 0
.
Exemple #1 Exemple avec mysql_fetch_row()
<?php
$result = mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!$result) {
echo 'Impossible d\'exécuter la requête : ' . mysql_error();
exit;
}
$row = mysql_fetch_row($result);
echo $row[0]; // 42
echo $row[1]; // la valeur du champ email
?>
Note: Cette fonction définit les champs NULL à la valeur PHP
null
.
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