This is a discussion on Can't get SHOW TABLES to work ! within the MySQL Database forums, part of the Database Forums category; Hi, I'm using PHP, MYSQL My code - - - $donor_db = "donor_database"; $new_db = "new_database"; $db_conn = mysql_connect($host, $user, $...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I'm using PHP, MYSQL My code - - - $donor_db = "donor_database"; $new_db = "new_database"; $db_conn = mysql_connect($host, $user, $pass); //get a list of all tables in the donor database mysql_select_db($donor_db, $db_conn); $query2 = "Show tables from ".$donor_db; $result2 = mysql_query($query2); $array2 = mysql_fetch_array($result2); //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 My problem 2 - - - while ($array2 = mysql_fetch_row($result2)) { echo $array2[0]."<br>"; } //in the browser this returns 39 table names excluding the first one (accounts) TIA - Any help much appreciated |
|
|||
|
== Quote from Robbo (ian@fds7.com)'s article
> Hi, > I'm using PHP, MYSQL > My code - - - > $donor_db = "donor_database"; > $new_db = "new_database"; > $db_conn = mysql_connect($host, $user, $pass); > //get a list of all tables in the donor database > mysql_select_db($donor_db, $db_conn); > $query2 = "Show tables from ".$donor_db; > $result2 = mysql_query($query2); > $array2 = mysql_fetch_array($result2); > //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 > My problem 2 - - - > while ($array2 = mysql_fetch_row($result2)) > { > echo $array2[0]."<br>"; > } > //in the browser this returns 39 table names excluding the first one > (accounts) > TIA - Any help much appreciated this is a PHP problem! -- POST BY: lark with PHP News Reader |
|
|||
|
On Jul 16, 4:52 pm, lark <ham...@sbcglobal.net> wrote:
> == Quote from Robbo (i...@fds7.com)'s article > > > > > > > Hi, > > I'm using PHP, MYSQL > > My code - - - > > $donor_db = "donor_database"; > > $new_db = "new_database"; > > $db_conn = mysql_connect($host, $user, $pass); > > //get a list of all tables in the donor database > > mysql_select_db($donor_db, $db_conn); > > $query2 = "Show tables from ".$donor_db; > > $result2 = mysql_query($query2); > > $array2 = mysql_fetch_array($result2); > > //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 > > My problem 2 - - - > > while ($array2 = mysql_fetch_row($result2)) > > { > > echo $array2[0]."<br>"; > > } > > //in the browser this returns 39 table names excluding the first one > > (accounts) > > TIA - Any help much appreciated > > this is a PHP problem! > -- > POST BY: lark with PHP News Reader- Hide quoted text - > > - Show quoted text - Great, they - the PHP group tell me it's a Mysql problem - which is why I posted here ! Thanks anyway |
|
|||
|
On Mon, 16 Jul 2007 21:24:33 +0200, Robbo <ian@fds7.com> wrote:
>> this is a PHP problem! >> > > Great, they - the PHP group tell me it's a Mysql problem - which is > why I posted here ! Indeed just a PHP-issue. Answered in comp.lang.php -- Rik Wasmus |
|
|||
|
Am 16.07.2007, 12:08 Uhr, schrieb Robbo <ian@fds7.com>:
> Hi, > > I'm using PHP, MYSQL > > My code - - - > > $donor_db = "donor_database"; > $new_db = "new_database"; > $db_conn = mysql_connect($host, $user, $pass); > > //get a list of all tables in the donor database > mysql_select_db($donor_db, $db_conn); > $query2 = "Show tables from ".$donor_db; > $result2 = mysql_query($query2); > $array2 = mysql_fetch_array($result2); > > //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 > > > My problem 2 - - - > > while ($array2 = mysql_fetch_row($result2)) > { > echo $array2[0]."<br>"; > } > > //in the browser this returns 39 table names excluding the first one > (accounts) > > TIA - Any help much appreciated > Concerning problem 2: If you execute both problematic parts in one script, the first mysql_fetch_row has already fetched the first row from the result resource, which is "accounts". It cannot turn up in the second loop unless you use my_sql_data_seek to reposition the index for array2 before. I am still a beginner, so I can't tell about problem 1. -- |
|
|||
|
Am 16.07.2007, 12:08 Uhr, schrieb Robbo <ian@fds7.com>:
> Hi, > > I'm using PHP, MYSQL > > My code - - - > > $donor_db = "donor_database"; > $new_db = "new_database"; > $db_conn = mysql_connect($host, $user, $pass); > > //get a list of all tables in the donor database > mysql_select_db($donor_db, $db_conn); > $query2 = "Show tables from ".$donor_db; > $result2 = mysql_query($query2); > $array2 = mysql_fetch_array($result2); > > //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 > > > My problem 2 - - - > > while ($array2 = mysql_fetch_row($result2)) > { > echo $array2[0]."<br>"; > } > > //in the browser this returns 39 table names excluding the first one > (accounts) > > TIA - Any help much appreciated > Concerning problem 2: If you execute both problematic parts in one script, the first mysql_fetch_row has already fetched the first row from the result resource, which is "accounts". It cannot turn up in the second loop unless you use my_sql_data_seek to reposition the index for array2 before. I am still a beginner, so I can't tell about problem 1. -- -- Erstellt mit Operas revolutionärem E-Mail-Modul: http://www.opera.com/mail/ |