Question: I need to add a counter to the loop as well as pulling contents. What is the syntax for adding the "and for ($ColCount = ColCount + 1)"

```
<?php $ColCount = 0?>
<!--get artwork thumbnails --> 
<?php
$dbname = 'pdartist2';
$table = 'artwork';
// query
$result = mysql_query("SELECT AID, ThumbFilePath, Title, DisplayOrder FROM artwork where SCID = '$SCID' ") or die(mysql_error());
while($row = mysql_fetch_row($result))
{
    foreach($row as $cell)
    and for ($ColCount = ColCount + 1) 

echo "$ColCount", "$cell";
}
mysql_free_result($result);
?>

```

Answer: 
I have no idea if that's valid in PHP. Maybe all it is is a forgotten `$` sign before `ColCount`. But you could just do it the normal way:

```
foreach($row as $cell) {
    $ColCount++;

    echo $ColCount . $cell;
}

$ColCount = 0;

```
If you're trying to count the number of columns in each row, then 

```
while($row = mysql_fetch_row($result)) {
   $colCount += count($row);
}

```

though I fail to see point of this. an SQL result set is a perfectly rectangular array. Variable number of rows, but every row will ALWAYS have the same number of fields as all the other rows in the result set. You'd only have to count the columns ONCE and cache that value.