You can use this:
<?php
for ($s = 0; $s < $r[4]; ++$s)
{
$name = ${"row".$s}[2]; //Here is my problem
if (${"row".$s}[45] == 1)
{
echo "<td class='nameSelect' colspan='6'>$name</td>";
}
else
{
echo "<td colspan='6'>$name</td>";
}
}
?>
For more information check Variable variables on php.net