Hello Scott,
Tuesday, 13 March 2001, you wrote:
SK> I fairly new to php and have a question about mysql and arrays.
SK> What I am trying to do is pull multiple rows of data out of a mysql database
SK> and I need to use that data as input for another table. I have tried to use
SK> mysql_fetch_array and have it write to the new table inside a while loop, but
SK> it only enters the first row of data into the new database.
SK> I have also tried to create an array from the data and use that with a
SK> foreach loop to input into a new database. Any suggestions on how to do this
SK> properly?
Well, the following code outputs the contents of a mysql table to an
html table. It's not too hard to adapt it to what you want...
HTH
Mark
<?
include("login_details");
mysql_connect($server,$user,$password);
mysql_select_db('yourdb'); // Change to the target database
$customers = mysql_query("select * from customers");
?>
<html>
<body>
<h1>List of customers currently saved in the database</h1>
<p>
Rows retrieved: <? echo mysql_num_rows($customers) . "\n"; ?>
</p>
<p>
<table border=1>
<?
while ($customer = mysql_fetch_row($customers)) // Loop through all rows returned
{
echo " <tr>\n";
while ($field = each($customer)) //Loop through all the fields in this row
print " <td><i>" . current($field) . "</i></td>\n";
echo " </tr>\n";
}
?>
</table>
</p>
</body>
</html>
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]