phpwimp

Php Script failing to continue after a for(;;) loop


I have a PHP script that queries a database and fills out some <option> tags inside a <select> tag. See code below:

$stmt = sqlsrv_query($dbc, $tsql, $params, $dbcOptions);
if($stmt === false) {
        die ( print_r (sqlsrv_errors(), true));
}
$rows = sqlsrv_num_rows($stmt);
#echo $rows.'rows';
echo '<!--'.$rows.'-->';
echo '<select onchange="getNamesByDep(this.value)">';
echo '<option value="">Select a Department. . .</option>';

for ($i = 1; i <= $rows; $i++)
{
        if(sqlsrv_fetch($stmt) !== false)
        {
                $DepName = sqlsrv_get_field($stmt,0);
                echo '    <option row="'.$i.'" value="'.$DepName.'">'.$DepName.'</option>'."\r\n";
        }
}
echo '</select>';
echo 'Debugging';

It never echos </select> or Debugging to the HTML of the page.

I know that I configured $dbc, $tsql, $params, and $dbcOptions correctly because I am getting the desired results from my query.

Do I have a syntax error that my web server (WIMPServer) isn't catching?


Solution

  • I think I found it:

    for ($i = 1; i <= $rows; $i++)
    

    You forgot the dollar sign before the second i. It should be like this:

    for ($i = 1; $i <= $rows; $i++)