Can't get SHOW TABLES to work !

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, $...


Go Back   Usenet Forums > Database Forums > MySQL Database

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 07-16-2007
Robbo
 
Posts: n/a
Default Can't get SHOW TABLES to work !

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

Reply With Quote
  #2 (permalink)  
Old 07-16-2007
lark
 
Posts: n/a
Default Re: Can't get SHOW TABLES to work !

== 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
Reply With Quote
  #3 (permalink)  
Old 07-16-2007
Robbo
 
Posts: n/a
Default Re: Can't get SHOW TABLES to work !

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


Reply With Quote
  #4 (permalink)  
Old 07-16-2007
Rik
 
Posts: n/a
Default Re: Can't get SHOW TABLES to work !

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
Reply With Quote
  #5 (permalink)  
Old 07-18-2007
P.A.
 
Posts: n/a
Default Re: Can't get SHOW TABLES to work !

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.

--
Reply With Quote
  #6 (permalink)  
Old 07-19-2007
P.A.
 
Posts: n/a
Default Re: Can't get SHOW TABLES to work !

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/
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 09:09 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0