"Miles Thompson" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> Jonathan .. see below.
> At 08:38 PM 5/18/01 +0000, Jonathan Duncan wrote:
> >Miles
> >
> >Thank you for the response.  I did some debugging and the value of $dbs
is 2.
> >
> >I am not sure of what example you are referring to.  I am not using the
> >manual currently, although I have the PDF version of it.
>
> http://www.php.net/mysql_list_dbs
> for on line version, with annotations!
>
I tried the example found on the site:

  while ($row = mysql_fetch_object($dbs)) {
    echo $row->Database . "\n";
  }

And the results were null.  It listed nothing.  I have a question about this
example, what is the "->" supposed to do?


>
> >The incrementation of $db_num happens on line 24 but I only listed the
first
> >10 lines because it seems to be a problem within the first 10 lines as
the
> >error message indicates.
> >
> >If I change line 10 from:
> >
> >$tables = mysql_list_dbs($db_names[$db_num])
> >
> >to:
> >
> >$tables = mysql_list_dbs()
> >
> >the script runs and gives me a list of the databases redundantly:
> >
> >-mysql
> >-test
> >    mysql
> >    test
> >    twignud
> >-twignud
> >    mysql
> >    test
> >    twignud
>
> Cool! Although it's not what you want. <g>.
> But what is it telling us? We're just running through two loops, but
really
> asking for the same information each time, if I interpret it correctly.
>
> And if you look at your code, you have two nested loops, doing essentially
> the same thing - listing the databases.
>
That is pretty much what I am trying to do.  I want to list each database
and then the tables within those databases.

>
> ><?
> >   $connection = mysql_connect("localhost", "user", "password") or die
> >("Couldn't connect.");
> >   $dbs = mysql_list_dbs($connection) or die("Couldn't list databases.");
> >   $db_list = "<UL>";
> >   $db_num = 0;
> >   while ($db_num < mysql_num_rows($dbs)) {
> >     $db_names[$db_num] = mysql_tablename($dbs, $db_num);
> >         $db_list .= "<LI>$db_names[$db_num]";
> >         if (($db_names[$db_num] != "mysql") && ($db_names[$db_num] !
> >= "tempdata")) {
> >         $tables = mysql_list_dbs($db_names[$db_num]) or die("Couldn't
list
> >databases.");
> >           $tables = mysql_list_dbs() or die("Couldn't list databases.");
> >           $table_list = "<UL>";
> >           $table_num = 0;
> >           while ($table_num < mysql_num_rows($tables)) {
> >             $table_names[$table_num] = mysql_tablename($tables,
$table_num);
> >                 $table_list .= "<LI>$table_names[$table_num]";
> >                 $table_num++;
> >           }
> >           $table_list .= "</UL>";
> >         }
> >         $db_list .= "$table_list";
> >         $db_num++;
> >   }
> >   $db_list .= "</UL>";
> >?>
> >
> >This is minus my debugging additions.  I tried to get info from
> >$mysql_tablename but it came up blank every way I tried it.  It is as
though
> >nothing is getting passed into $mysql_tablename.
>
> That's strange, because this annotation came from zak@php:
> [Editor's Note: mysql_db_name(), mysql_dbname() and mysql_tablename()
>   are all aliases for mysql_result() and should behave in exactly the same
>   fashion. [EMAIL PROTECTED]]
>
> Use mysql_db_name() instead of mysql_tablename() to read databases.
> http://php.net/manual/en/function.mysql-db-name.php
>
> So this should give us a list of keys and databases:
> while( $row = mysql_fetch_array( $dbs ) )
> {
>          echo $row[ 0 ];
>          echo $row[ 1 ];
> }
>

while($row = mysql_fetch_array($dbs)) {
    echo "Row 0 is ", $row[0];
 echo "Row 1 is ", $row[1];
  }

Returns:

Row 0 is mysqlRow 1 is Row 0 is testRow 1 is Row 0 is twignudRow 1 is

-IE-

Row 0 is mysql
Row 1 is
Row 0 is test
Row 1 is
Row 0 is twignud
Row 1 is

> I'm wondering, if $row[ 0 ] returns the name of the database, and $row[
1 ]
> returns "array". (Or vice versa.) If so, we should be able to nest another
> while () in there and fetch the table names. (If that's your intention.)
>
> I'll warn you that I get lost in multi-dimensional arrays very quickly,
and
> I'm freelancing this off the top of my head.
>
It seems that Row 1 doesn't have anything which may be the source of the
problem.  What do you think of this?


> >Does this clarify anything in your mind?  I am taking this script
straight
> >from a book.  However, the book is designed for PHP 4 and I am using PHP
> >3.0.16, although I don't know if that would make a difference.
>
> Shouldn't, but is there any reason why you can't go to 4.0.5? Why not get
> the database names loop working first, and then go for the table names, a
> divide and conquer approach.
>
Sounds like a good plan, I will see what I can do.


> >Thank you very much for your help,
> >Jonathan
>
> My pleasure - you're digging on it too.
> Miles
>
Yep, I love this stuff!



-- 
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]

Reply via email to