note 8436 deleted from function.mysql-fetch-row by didou

From: Date: Thu, 05 Feb 2004 14:57:23 +0000
Subject: note 8436 deleted from function.mysql-fetch-row by didou
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-64690@lists.php.net to get a copy of this message
Note Submitter: php-general@lists.php.net ---- # Here is an example of how mysql_fetch_row is used. # Connect to your MySQL database server mysql_connect ('localhost', 'username', 'password') or die ('I cannot connect to the database. Make sure that mysql is installed and that you are trying to log in as a valid user.'); # Select a default database to work with mysql_select_db ('database_name') or die ('The database specified in database_name must exist and must be accessible by the user specified in mysql_connect'); # make a query on a table in your database $query = "SELECT * FROM table_name"; $query_result_handle = mysql_query ($query) or die ('The query failed! table_name must be a valid table name that exists in the database specified in mysql_select_db'); # make sure that we recieved some data from our query $num_of_rows = mysql_num_rows ($query_result_handle) or die ("The query: '$query' did not return any data"); print "The query: '$query' returned $num_of_rows rows of data.<br>"; # use mysql_fetch_row to retrieve the results for ($count = 1; $row = mysql_fetch_row ($query_result_handle); ++$count) { print "<br><b>Fetching row #$count from the query.</b><br>"; print "Value stored at the first index position of \$row: '$row[0]'<br>"; print "Value stored at the second index position of \$row: '$row[1]'<br>"; print "Value stored at the third index position of \$row: '$row[2]'<br>"; print "Value stored at the fourth index position of \$row: '$row[3]'<br>"; print "Value stored at the fifth index position of \$row: '$row[4]'<br>"; print "Value stored at the sixth index position of \$row: '$row[5]'<br>"; print '...<br>'; }

« previous php.notes (#64690) next »