Matt, Perhaps I could elaborate for you. When you run a mysql query through php the function returns a result variable. This is not unlike a cursor that you would use in oracle programming. This result set contains all the rows returned by the query but you must take it a step further to gather the values from the result set. A call to mysql_fetch_row() will return a different "row" from the result set each time it is called until it is empty. It's commonly placed in a while() loop so the function will continue to be called until mysql_fetch_row() returns false. For each interation of the loop an array is returned into $row my mysql_fetch_result() that is indexed numerically by row number. These row numbers will match the order of the columns as specified in your select clause or by column order in the database if you did a select *. An alternative to mysql_fetch_row would be mysql_fetch_array or mysql_fetch_assoc. These functions return an array as well but it is associative meaning the elements can be accessed by column name. For example: $row['name']. I personally prefer this method because it makes the code a bit easier to read and I don't have to remember the order of columns. The numerically indexed arrays are handy for dumping table structures though because you can loop off the array size and don't have to change your code if you change your database schema. This latter technique is the one used by Bas in his example.
Hope that clears things up a bit. Jason Cox ----- Original Message ----- From: "DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2)" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, February 28, 2002 6:55 AM Subject: RE: [PHP] Probably basic but seems advanced to me, PHP/SQL generation. > > Hi Baz, > > Thanks for mailing back, would you care to explain this a little more so I > understand whats going on and how to use it > > I can see that you are fetching the results of select * from - into and > array. and while there is records in the array you are echoing data, but I > am not sure on whats going on, and how to generate the table from these > results. > > thanks, > > Matt. > > > -----Original Message----- > From: Bas Jobsen [mailto:[EMAIL PROTECTED]] > Sent: Thursday, February 28, 2002 1:59 PM > To: DARCY,MATTHEW (Non-HP-UnitedKingdom,ex2); [EMAIL PROTECTED] > Subject: Re: [PHP] Probably basic but seems advanced to me, PHP/SQL > generation. > > > while ($row=mysql_fetch_row($result)) > { > echo "1 $row[0]" > for($x=1; $x<count($row); $x++) > if(!empty($row[$x])) > { > echo $x+1; > echo " ".$row[$x]; > } > } > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php