|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
how to find the number of columns for the particular table thru sql query?
|
|
#2
|
||||
|
||||
|
There are a couple ways you can do it.
$result = mysql_query("SHOW COLUMNS FROM your_table"); $num_colums = mysql_num_rows($result); Or... $result = mysql_query("SELECT * FROM your_table LIMIT 1"); $num_colums = mysql_num_fields($result); The show columns command gives you more into about what type the columns are, whether it's a key or not, etc. Try it from the command line. The second way is better if you're already selecting something from the database, then you can count the fields before you start processing them. One warning though, I'm not sure how it handles a null field in the result, it might not count it??? I'm not sure, the best way is to test... ---John Holmes... Since there were a couple ways to do it, I was nice, but I found all the answers in the manuals. ![]() ------------------ ************************************************************* * The manual can probably answer 90% of your questions... * * PHP Manual. www.php.net/manual * MySQL Manual: www.mysql.com/documentation/mysql/bychapter ************************************************************* [This message has been edited by SepodatiCreations (edited October 10, 2000).] |
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > no of columns |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|