suche nach in der

mysql_field_flags> <mysql_fetch_object
Last updated: Fri, 18 May 2012

view this page in

mysql_fetch_row

(PHP 4, PHP 5)

mysql_fetch_rowLiefert einen Datensatz als indiziertes Array

Beschreibung

array mysql_fetch_row ( resource $result )

Liefert ein numerisch indizertes Array, das der geholten Zeile entspricht und bewegt den internen Datenatzzeiger vorwärts.

Parameter-Liste

Ergebnis

Das Ergebnis Ressource, das ausgewertet wird. Dieses Ergebnis kommt von einem Aufruf von mysql_query().

Rückgabewerte

Gibt ein numerisches Array von Zeichenketten zurück, das der gelesenen Zeile entspricht oder FALSE falls keine weiteren Zeilen vorhanden sind.

mysql_fetch_row() liefert einen Datensatz aus dem Anfrageergebnis mit der übergebenen Kennung. Der Datensatz wird als Array geliefert. Jedes Feld wird in einem Array-Offset abgelegt, der Offset beginnt bei 0.

Beispiele

Beispiel #1 Eine Zeile mit mysql_fetch_row() holen

<?php
$result 
mysql_query("SELECT id,email FROM people WHERE id = '42'");
if (!
$result) {
    echo 
'Konnte Abfrage nicht ausführen: ' mysql_error();
    exit;
}
$row mysql_fetch_row($result);

echo 
$row[0]; // 42
echo $row[1]; // der email Wert
?>

Anmerkungen

Hinweis: Diese Funktion setzt NULL-Felder auf den PHP Wert-NULL.

Siehe auch



add a note add a note User Contributed Notes
mysql_fetch_row
m dot s at programmers-online dot net
17-Nov-2005 10:56
The following function to read all data out of a mysql-resultset, is may be faster than Rafaels solution:

<?
function mysql_fetch_all($result) {
   while(
$row=mysql_fetch_array($result)) {
      
$return[] = $row;
   }
   return
$return;
}
?>
mysql at polyzing dot com
13-Jul-2003 12:05
It is probably worth pointing out that the array elements will actually be of type string, OR NULL if the field is null in the database.

Thus, either use a double equal comparison to look for empty or null

Or, use a triple equal comparison to be able to distinguish the two cases

e.g.

if ($field === '') echo "Empty, not NULL\n";

if ($field === NULL) echo "NULL\n";

if ($field == '') echo "Empty or NULL\n";
michael and then an at sign wassupy.com
08-Apr-2003 09:09
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.
a at simongrant dot org
06-Feb-2002 02:10
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 dot net at sury dot cz
06-Jun-2001 08:40
You could also use this language construct with mysql_fetch_row:

while (list($first, $second) = mysql_fetch_row($resource)) {
[...]
}
doug at melonn dot com
13-May-2001 10:57
you can also use mysql_fetch_row() like this if you want to display inumerable results the same way:

#connect to the server and select db
mysql_connect("host","username","pass");
mysql_select_db("dbname");

#query the db
$query = "SELECT * FROM table";
$result = mysql_query($query)
or die(mysql_error());

#display results
while($i = mysql_fetch_row($result)) {
echo $i[0];
echo $i[1];
.....
}

and so forth...

mysql_field_flags> <mysql_fetch_object
Last updated: Fri, 18 May 2012