语法错误,意外的“}”,期望while (T_WHILE)正在杀死我。

时间:2021-12-18 23:07:42

I am trying to convert some pretty intense PHP pages to mysqli from mysql for version 5 of mySQL. Don't want to use PDO at this time.

我试图将一些非常紧凑的PHP页面从mysql转换为mysql版本5。不要在这个时候使用PDO。

Database is there, a simple generic query works and displays on PHP page by converting all the mysql syntax to mysqli syntax, but for the likes of me I can't figure out where to fix this error. I says it is happening on line 449, and I've tried everything above and below that line. Below is the error and below that is the code for lines 432 thru 449. This page works fine in mySQL 4 database.

数据库在那里,一个简单的泛型查询在PHP页面上显示,通过将所有mysql语法转换为mysqli语法,但是对于我这样的人,我不知道该如何修正这个错误。我说它发生在第449行,我已经试过了这条线上面和下面的所有东西。下面是错误,下面是第432至449行的代码。这个页面在mySQL 4数据库中运行良好。

syntax error, unexpected '}', expecting while (T_WHILE) in C:\inetpub\wwwroot\xxx\carpoollocations.php on line 449

语法错误,意外的“}”,在C:\inetpub\wwwroot\xxx\carpoollocation中等待(T_WHILE)。php在第449行

Line 332-449:

332 - 449行:

            } while ($myrowsel = mysqli_fetch_array($result,MYSQLI_BOTH));
echo "</TABLE>";
/*----------------------------------------------------------------
PAGING LINK - THIS IS USED FOR NEXT/PREVIOUS X RECORDS
----------------------------------------------------------------*/

    if ($reccount > 10) {
//IF THERE ARE MORE THAN 10 RECORDS PAGING
    $ttlpages = ($reccount / 10);
    if ($page < $ttlpages) {
    ?>

<HR>    <br>
<A HREF="<?php echo $thispage; ?>?posting=yes&page=<?php echo $page; ?>&reccount=<?php echo $reccount; ?>&searchcrit=<?php echo $searchcrit; ?>&<?php echo $pagevars; ?>">Next <?php echo $pagenorecords; ?> Records >></a> <br>

    <?php 
    } //END IF AT LAST PAGE
    } //END IF RECCOUNT > 10

__________________________________________________________________ Updated with new information that would look like to be the answer: no "do while" loop in msqli.

__________________________________________________________________更新新的信息,样子回答:msqli没有“同时”循环。

Thanks everyone for looking. Well, it's not the semi-colon after the while statement. Took it off with same error occurring. I couldn't figure out a unexpected '}' no matter what I removed or added. Also all curlies seemed balanced. Since this block occurs all over the page with no syntax errors except the one that was below a while statement, I decided to isolate the "do while" loop into a simple one since the error mentions T_WHILE. I changed it and put the while at the top of the loop and it worked. Putting it back at the bottom created a different error.

感谢每个人。好了,这不是半冒号之后的语句。在同样的错误发生时,把它拿掉了。无论我删除或添加什么,我都无法找到一个意想不到的“}”。而且所有的诅咒似乎都是平衡的。由于这个块出现在页面的所有地方,除了在while语句下面的错误之外,没有语法错误,所以我决定将“do while”循环隔离为一个简单的循环,因为错误提到了T_WHILE。我改变了它,把while放在了循环的顶部,它起作用了。把它放回底部会产生一个不同的错误。

So this runs and shows all the data from 2 columns.

这就运行并显示了来自2列的所有数据。

while ( $row = mysqli_fetch_array($result, MYSQLI_ASSOC) ) {

                  echo $row["id"]." ---- ".$row["Location"]."<br />";

    }

This runs and creates an error "Undefined variable: row": Now, this is a different error, but is a start. I will work on changing the loop tomorrow. I notice that the syntax error above occurs even if I put "die();" way up above near the top of the page.

这将运行并创建一个错误“未定义的变量:row”:现在,这是一个不同的错误,但是是一个开始。明天我将努力改变这个循环。我注意到,即使我将“die()”放在页面顶部的上方,也会出现语法错误。

do {

              echo $row["id"]." ---- ".$row["Location"]."<br />";

}while ( $row = mysqli_fetch_array($result, MYSQLI_ASSOC) )

Any thoughts if I am going in the right direction?

如果我往正确的方向走,有什么想法吗?

2 个解决方案

#1


1  

            } while ($myrowsel = mysqli_fetch_array($result,MYSQLI_BOTH));<!--Change to {
echo "</TABLE>";
/*----------------------------------------------------------------
PAGING LINK - THIS IS USED FOR NEXT/PREVIOUS X RECORDS
----------------------------------------------------------------*/

    if ($reccount > 10) {
//IF THERE ARE MORE THAN 10 RECORDS PAGING
    $ttlpages = ($reccount / 10);
    if ($page < $ttlpages) {
    ?>

<HR>    <br>
<A HREF="<?php echo $thispage; ?>?posting=yes&page=<?php echo $page; ?>&reccount=<?php echo $reccount; ?>&searchcrit=<?php echo $searchcrit; ?>&<?php echo $pagevars; ?>">Next <?php echo $pagenorecords; ?> Records >></a> <br>

    <?php 
    } //END IF AT LAST PAGE
    } //END IF RECCOUNT > 10

On your while loop you ended it with a ; instead of a { simple mistake and easy to make, but fixing that should correct the issue. If it still throws an error afterwards you may have to add a new } to the end of the script there to close out the while loop.

在你的while循环中,你以a结束它;而不是一个简单的错误和容易做的,而是纠正应该纠正这个问题。如果它仍然抛出一个错误,那么您可能需要在脚本的末尾添加一个新的}来关闭while循环。

#2


0  

You get undefined variable $row because do...while loop will process the code which in do{ } first and in the first time the variable $row is not registered and then it will process the while() and come back to do{} 2nd time it will work but there will be an error you should directly use while loop for mysqli or mysql

你会得到未定义的变量$row,因为…while循环将处理的代码在{ }第一和第一次变量$行不是注册然后它会过程而()和{ } 2日时间回来做它会工作,但将会有一个错误,你应该直接使用while循环mysqli或mysql

#1


1  

            } while ($myrowsel = mysqli_fetch_array($result,MYSQLI_BOTH));<!--Change to {
echo "</TABLE>";
/*----------------------------------------------------------------
PAGING LINK - THIS IS USED FOR NEXT/PREVIOUS X RECORDS
----------------------------------------------------------------*/

    if ($reccount > 10) {
//IF THERE ARE MORE THAN 10 RECORDS PAGING
    $ttlpages = ($reccount / 10);
    if ($page < $ttlpages) {
    ?>

<HR>    <br>
<A HREF="<?php echo $thispage; ?>?posting=yes&page=<?php echo $page; ?>&reccount=<?php echo $reccount; ?>&searchcrit=<?php echo $searchcrit; ?>&<?php echo $pagevars; ?>">Next <?php echo $pagenorecords; ?> Records >></a> <br>

    <?php 
    } //END IF AT LAST PAGE
    } //END IF RECCOUNT > 10

On your while loop you ended it with a ; instead of a { simple mistake and easy to make, but fixing that should correct the issue. If it still throws an error afterwards you may have to add a new } to the end of the script there to close out the while loop.

在你的while循环中,你以a结束它;而不是一个简单的错误和容易做的,而是纠正应该纠正这个问题。如果它仍然抛出一个错误,那么您可能需要在脚本的末尾添加一个新的}来关闭while循环。

#2


0  

You get undefined variable $row because do...while loop will process the code which in do{ } first and in the first time the variable $row is not registered and then it will process the while() and come back to do{} 2nd time it will work but there will be an error you should directly use while loop for mysqli or mysql

你会得到未定义的变量$row,因为…while循环将处理的代码在{ }第一和第一次变量$行不是注册然后它会过程而()和{ } 2日时间回来做它会工作,但将会有一个错误,你应该直接使用while循环mysqli或mysql