On Monday 22 April 2002 12:54, Vania Smrkovski wrote:
> Hello, folks, and I apologize in advance if I break any rules here.  This
> is my first post on this list and I couldn't find any archive to review
> existing posts for the answer to this question.


> a) How would you change the following the automatically find the tables and
> run through the iteration.  

Using mysql running the query:

  SHOW tables;

Would return the names of the tables in the currently selected database.

> I'm new at PHP, and I learn by doing, so
> forgive me for not doing the RTFM thing, but I just haven't found the
> answer yet. 

Does that mean you haven't RTFM so you haven't found the answer yet?

> So instead I created a table called tableNames with one field,
> which I personally populated with the names of all tables.
>     How should I have done it so that wouldn't be necessary.

See above.

> b)  When I grab the values of the table names using my prepared table
> tableNames, I couldn't figure out how to get the TEXT value of that record.
> When I put in a debug statement, all I got was a value of "Array", rather
> than a name of a table.  

It helps to RTFM. In any case the name of the function mysql_fetch_array() 
kind of gives the game away :)

> You'll see below that I hacked a work-around by
> using a "foreach()" statement, which works flawlessly.

That is common practice when dealing with arrays.

>     How can I grab a specific field of an array without using a foreach()?

>     while ($line = mysql_fetch_array($result, MYSQL_ASSOC))

If you know the names of the fields, then you can access them directly by:

  $value_of_field = $line['name_of_field'];

If you had used:  

  while ($line = mysql_fetch_array($result, MYSQL_NUM))

Then you would have to reference the fields using:

  $value_of_field_0 = $line[0];

Remember the manual is your friend. If you haven't already done so, download 
a copy (it's available in various formats) and make use of it!

Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

I don't know half of you half as well as I should like; and I like less
than half of you half as well as you deserve.
                -- J. R. R. Tolkien

PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to