Count
Posted: Fri Nov 12, 2004 6:02 am
Is there a way to count the number of columns in a table?
Even if the table has no data.
Even if the table has no data.
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
SELECT count(*) FROM blah WHERE moo = 'yes';Code: Select all
SHOW COLUMNS FROM sometableCode: Select all
<?php
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('test');
$sql = 'desc cities';
$result = mysql_query($sql);
$numCols = mysql_num_rows($result);
echo "There are $numCols columns in table 'cities'";
?>Code: Select all
<?php
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('test');
$sql = 'SHOW COLUMNS FROM cities';
$result = mysql_query($sql);
$numCols = mysql_num_rows($result);
echo "There are $numCols columns in table 'cities'";
?>