[PHP] Php / MySQL DESC tablename

2007-01-21 Thread Beauford
Hi,

First off thanks to everyone for the previous help. I managed to get it
sorted out and used several of the suggestions made.

I am trying to do a DESC table_name using PHP so it looks like it would it
you did it from the command line.

i.e. 

| Field | Type | Null | Key | Default | Extra  |
+---+--+--+-+-++
| id| int(11)  | NO   | PRI | NULL| auto_increment | 
| name  | varchar(30)  | NO   | | NULL|| 

What I have found is that the following does not work the way I would have
thought.

$query = DESC table .$currenttb;
$result = mysql_query($query);

while ($row = mysql_fetch_row($result)) {
etc.

I have found something that works, but it is still not like the above and is
really bulky. I can not get the type (varchar, etc) to show like above, it
will show string, blob, etc, and the last problem is it puts the last 4
fields in one variable (flags).

Does anyone know of a way to get this to output as shown above. I am putting
this into a form for editing, so I need everything in the proper places.

Thanks


Here is the entire code:

mysql_select_db($_SESSION['currentdb']);

$result = mysql_query(SELECT * FROM .$_SESSION['currenttb']);
$fields = mysql_num_fields($result);
$rows  = mysql_num_rows($result);
$table  = mysql_field_table($result, 0);

for ($i=0; $i  $fields; $i++) {
$type  = mysql_field_type($result, $i);
$name  = mysql_field_name($result, $i);
$len  = mysql_field_len($result, $i);
$flags = mysql_field_flags($result, $i);
echo all the filds
}

This outputs (depending on the order you echo them):

username string 50 [not_null primary_key auto_increment]  value in [] is one
value.

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



Re: [PHP] Php / MySQL DESC tablename

2007-01-21 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2007-01-21 03:05:49 -0500:
 I am trying to do a DESC table_name using PHP so it looks like it would it
 you did it from the command line.
 
 i.e. 
 
 | Field | Type | Null | Key | Default | Extra  |
 +---+--+--+-+-++
 | id| int(11)  | NO   | PRI | NULL| auto_increment | 
 | name  | varchar(30)  | NO   | | NULL|| 
 
 What I have found is that the following does not work the way I would have
 thought.
 
   $query = DESC table .$currenttb;
   $result = mysql_query($query);

   while ($row = mysql_fetch_row($result)) {
   etc.

DESC is not a sql command, it's specific to the mysql(1) command line
client.

 I have found something that works, but it is still not like the above and is
 really bulky. I can not get the type (varchar, etc) to show like above, it
 will show string, blob, etc, and the last problem is it puts the last 4
 fields in one variable (flags).

What you've found is similar to what mysql(1) does when you send
DESC mytable.

 Does anyone know of a way to get this to output as shown above. I am putting
 this into a form for editing, so I need everything in the proper places.

Finish your effort to produce the desired output. You're almost there.

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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