★ wanayoo — archive 1999 http://www.php.net/manual/function.mysql-fetch-row.phpNouvelle recherche | Portail wanayoo

PHP Home Page

Manual Table of Contents
Up to MySQL
Quick Reference
MySQL
* mysql_affected_rows
* mysql_change_user
* mysql_close
* mysql_connect
* mysql_create_db
* mysql_data_seek
* mysql_db_query
* mysql_drop_db
* mysql_errno
* mysql_error
* mysql_fetch_array
* mysql_fetch_field
* mysql_fetch_lengths
* mysql_fetch_object
* mysql_fetch_row
* mysql_field_name
* mysql_field_seek
* mysql_field_table
* mysql_field_type
* mysql_field_flags
* mysql_field_len
* mysql_free_result
* mysql_insert_id
* mysql_list_fields
* mysql_list_dbs
* mysql_list_tables
* mysql_num_fields
* mysql_num_rows
* mysql_pconnect
* mysql_query
* mysql_result
* mysql_select_db
* mysql_tablename
Manual: mysql_fetch_row
View the source code for this pageSearch the site



Previous page
 mysql_fetch_object
mysql_field_name 
Next page


mysql_fetch_row

mysql_fetch_row -- Get a result row as an enumerated array

Description

array mysql_fetch_row(int result);

Returns: An array that corresponds to the fetched row, or false if there are no more rows.

mysql_fetch_row() fetches one row of data from the result associated with the specified result identifier. The row is returned as an array. Each result column is stored in an array offset, starting at offset 0.

Subsequent call to mysql_fetch_row() would return the next row in the result set, or false if there are no more rows.

See also: mysql_fetch_array(), mysql_fetch_object(), mysql_data_seek(), mysql_fetch_lengths(), and mysql_result().


User Contributed Notes: mysql_fetch_row


richard.quinn@it-choice.de
28-Dec-1999 10:21
I am having problems with this when data begins with the null character. The following loops through records in a table and makes the
<option>
entries for a
<select>
element.
                while ($line = mysql_fetch_row($RCResultID)){
                        if ($Chosen==$line[0]){
                            $Selected="Selected";
                        } else {
                            $Selected="";
                        }
                        echo "<!-- $Zeile[0] $line[0] -->";
                        $retValue.="\t<OPTION $Selected value='".$line[0]."'>".htmlentities($line[1])."\n";
                }
If there are 20 records in the table, and ten of them befin "^^" (space space) then although I am told by mysql_num_rows that there are indeed 20 records, mysql_fetch_rows only returns 10 records. This may be a PHP problem, mysql itself has no problems delivering unusual records. This is driving me nuts - the only workaround I have is to catch the leading null cahrs in the input ans str_replace them. Then of course I have to catch the special case when outputting ... Ugh ugly.


richard.quinn@it-choice.de
28-Dec-1999 10:40
Sorry about the prvious post (I *did* surround the HTML with pre Tags). Anyway, it seems that under certain circumstances mysql_num_rows moves the cursor to record 1. This is a problem if you have assumed that the cursor is on record 0. The moral: Don't assume that PHP puts the DB cursor on record 0 after doing a row count.


arni@linux.is
26-Jan-2000 07:47
MYSQL_FETCH_ROW() is a good way to output data after selecting data from a mySQL server using MYSQL_QUERY(). Example:
$query = mysql_query("select field,field2,field3 from table");

while(list($field,$field2,$field3)=mysql_fetch_row($query)) {





arni@linux.is
26-Jan-2000 07:48
MYSQL_FETCH_ROW() is a good way to output data after selecting data from a mySQL server using MYSQL_QUERY(). Example:
$query = mysql_query("select field,field2,field3 from table");

while(list($field,$field2,$field3)=mysql_fetch_row($query)) {
   echo "$field $field2 $field3";
}



zep@indigo.org
28-Jan-2000 03:41
I'm having a problem with mysql_fetch_row. When I assign the output to an array and perform an isset($array[1]) on an element I know is empty (element 1). It shows it as being set. Thanks. - Matthew


mainframe@thewatercooler.com
16-Mar-2000 12:28
There's a slight difference between a variable not being set and a variable being NULL. for example:
$test='';
if(!isset($test)){ echo "I'm a NULL set variable!";};



venom@venom600.org
29-Mar-2000 11:05
I am writing a php/MySQL discussion forum and I'm having trouble printing out posts in the order that I want. The forum threads the posts, but my problem is that new posts are printed at the bottom of the forum, rather than the top. Is there a way to use mysql_fetch_row() to fetch a row in reverse order? My mysql query fetches all of the posts in order by date, oldest to newest, I need to print them out in the opposite direction...newest to oldest (top to bottom). Thanks.


onion_cfe@which.net
06-Apr-2000 03:22
my forum works recursively on each thread level. i can achieve what you want by adding ORDER BY date DESC to the SELECT query for the root level posts, and not for the other levels. That way, the posts appear newest at top, but the responses remain in the same order.


onion_cfe@which.net
06-Apr-2000 03:25
it is getting tiresome having to continually change the references to array element numbers whenever i change my tables. it seemed logical to me that since it is possibly to create arrays with text based keys in php3 that mysql might do the same and use the field names but it appears not. is there any way to make it easier (the closest i can find is never using SELECT * and always listing the fields I want in the order I want but its quite frustrating.


jamiebecker@ring0.com
18-Apr-2000 09:25
yes, you can use an ORDER BY statement in your SQL SELECT statement before it ever even gets to row to make sure that rows come out in the right order. A good tutorial on this is at http://w3.one.net/~jhoffman/sqltut.htm.


nucci@cac.psu.edu
05-May-2000 10:30
I have a MySQL table that looks as follows:
mysql> select sp_name from sp_frame;
+----------+
| sp_name  |
+----------+
| SP-BLUE  |
| SP-WHITE |
| SP-RED   |
+----------+
3 rows in set (0.00 sec)
When I try to reference this in a php script, I only get the first entry.

This is my code snippet:

  $query = "select sp_name from sp_frame";
  $res = mysql_query($query, $dbh) 
     or die ("Invalid Query to DB");
  $sp_frame_names = mysql_fetch_row($res);

echo "0: $sp_frame_names[0]  1:  $sp_frame_names[1]<br>";
This is the result:
0: SP-BLUE 1: 
Am I misinterpreting mysql_fetch_row() or is there some other problem? Thanks.


 About Notes


Previous page
 mysql_fetch_object
mysql_field_name 
Next page



Site Statistics


Who's responsible for this?
Top of this page

Site
Hosting:



Located in
United States
Elements of this website are subject to copyright.
Questions about installing or using PHP should be directed to one of the mailing lists.
Only questions about the website should be directed to webmaster@php.net.