Parse error: syntax error, unexpected T_ECHO

后端 未结 2 1499
-上瘾入骨i
-上瘾入骨i 2021-01-24 19:32

I\'ve been working on something for the past few days but this one bit of code perpetually throws an unexpected T_ECHO. My friends can\'t seem to find anything wrong with it an

相关标签:
2条回答
  • 2021-01-24 20:12

    You could use short tags to make this far more readable and likely less error prone.

    <?php while ($row = mysql_fetch_array($result, MYSQL_ASSOC)): ?>
        <tr>
            <td><?= $row["site_description"] ?></td>
            <td><?= $row["url"] ?></td>
            <td>
                <select>
                <?php while ($roar = mysql_fetch_array($categories, MYSQL_ASSOC)): ?>
                    <option><?= $roar["category"] ?></option>
                <?php endwhile; ?>
                </select>
            </td>
        </tr>
    <?php endwhile; ?>
    
    0 讨论(0)
  • 2021-01-24 20:12

    Try this...

    I think it may have been falling over because once you've parsed the categories resultset, for the first site, it comes up with nothing the next time you call mysql_fetch_array. So, doing this upfront and popping the results into a variable fixes that.

    I've added "\t" and "\n" to the strings to make the html format prettily in view source.

        $result = mysql_query("select * from tmp_sites");
    $categories = mysql_query("select * from tmp_cats");
    $select_options = "";
    while ($roar = mysql_fetch_array($categories, MYSQL_ASSOC)):
                      $select_options .= "\t\t<option value=\"". $roar["category"] ."\">". $roar["category"] ."</option>\n";
                    endwhile;
    echo "<table>";
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)):
                echo "\t<tr>\n";
                  echo "\t\t<td>". $row["site_description"] ."</td>\n";
                  echo "\t\t<td>". $row["url"] ."</td>\n";
                  echo "\t\t<td><select>\n";
                    echo $select_options;
                  echo "\t\t</select></td>\n";
                echo "\t</tr>\n";
              endwhile;
    echo "</table>"
    
    0 讨论(0)
提交回复
热议问题