RE: Tables etc .....

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> Does anyone have any example code of how to get column names from a
mysql
> table without knowing how many columns there are?  Basically what I
need
> to be able to do is to display the contents of a database without
knowing
> the column names as i'm trying to write something to manage my
databases
> and i'd rather try it myself rather than use phpmyadmin all the time
as
> you don't learn anything that way.

I have some example code I can send you off list, if you want, but it's
not that hard to figure out.

1. Issue query with mysql_query(). You do not need to know how many
columns there are or their name.

2. Use mysql_num_fields() to find out how many columns were returned.

3. Loop through the number returned in #2 with mysql_field_name() to get
the field names and create your "header" row. 

4. Loop through each row, fetching it with mysql_fetch_row().

5. You already know how many columns there are, so display $row[0] to
$row[num_fields] from the result of mysql_fetch_row in their own <td>
tags. 

That's it. Let me know if you want the example code. It does a little
more than this...

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



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


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux