|
Posted by Rik on 07/16/07 19:35
On Mon, 16 Jul 2007 21:28:15 +0200, Robbo <ian@fds7.com> wrote:
>> Hi,
>
>> I'm using PHP, MYSQL
>> My code - - -
>> $donor_db =3D "donor_database";
>> $new_db =3D "new_database";
>> $db_conn =3D mysql_connect($host, $user, $pass);
>> //get a list of all tables in the donor database
>> mysql_select_db($donor_db, $db_conn);
>> $query2 =3D "Show tables from ".$donor_db;
>> $result2 =3D mysql_query($query2);
>> $array2 =3D mysql_fetch_array($result2);
[1] Don't do this here... see later in the post.
>> //there are 40 tables in the donor database
>> My Problem 1 ---
>> foreach ($array2 as $table_name)
>> {
>> echo $table_name."<br>";
>> }
>> //in the browser this returns the first table listed twice - -
>> //
>> //accounts
>> //accounts
Indeed, mysql_fetch_array() will get both a numericallly indexed and an =
=
associative array. Use mysql_fetch_row() or mysql_fetch_assoc(), dependi=
ng =
on which of those you plan to use.
>> My problem 2 - - -
>> while ($array2 =3D mysql_fetch_row($result2))
>> {
>> echo $array2[0]."<br>";
>> }
>> //in the browser this returns 39 table names excluding the first on=
e
Indeed, because above it you allready fetch the first result at [1], so =
=
it's gone there. Don't do that and you'll be fine.
-- =
Rik Wasmus
[Back to original message]
|