Forum Moderators: coopster
$result = mysql_query($query) or die ("Error in query: $query. " .
mysql_error());
while ($row = mysql_fetch_row($result))
{
foreach ($row as $item)
$counter=++$i;
}
echo $counter;
But is there a way of counting the fields of just the first row (invariably the most populated row for all the tables)?
CREATE TABLE mytable (
myid INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
myfname CHAR(20),
mymname CHAR(20),
mylname CHAR(20),
PRIMARY KEY (myid)
);
INSERT INTO mytable VALUES (NULL, 'firstname', 'middlename', 'lastname');
--
-- returns 4 columns:
--
SELECT * FROM mytable;
--
-- returns 3 columns:
--
SELECT myfname, mymname, mylname FROM mytable;
--
-- counting this will also show 4 columns:
--
SHOW COLUMNS FROM mytable;
They are not indexed. They consist of a series of numbers along the top, and a series of numbers down the left hand side. The remaining fields are either NULL or "X". Basically they show whether a desired feature is available based on parameters shown in 2 axes.
$query = "SELECT * FROM $thisismytable";
$result = mysql_query($query) or die ("Error in query: $query. " .
$row = mysql_fetch_row($result);
$columnCount = count($row);
The above code produces the desired result, verified against the contents of specific tables.
The tables come from Excel, because they derive from calculations needed for offering a catalogue, and were not intended for the web, originally. Since then, I have been able to get away from the odd table needed in mysql by first deriving them in Access or Excel. But I realise I need to get more stuck into the subject. Thanks for your input - it's all adding to the mosaic that's beginning to form in my head.