PHP Parse错误:语法错误,意外T_IF
我看了很多其他问题,但我找不到自己的答案。
这是我的语法错误(未完成的T_IF):
I looked at many other questions, but I can't find my own answer in it. here is my syntax error (unexpeted T_IF):
while(($rij1 = mysql_fetch_object($result1))
and( if ($voornaam=NULL) {
$rij2 = ' ';}
elseif($voornaam!=NULL){
$rij2 = mysql_fetch_object($result2);})
我在语法之前看了一行,但是我找不到有什么问题...
有人知道吗?
I looked at the line before the syntax, but I couldn't find what is wrong... Does someone know it?
尝试将代码重写为:
while ($rij1 = mysql_fetch_object($result1))
{
if ($voornaam === NULL)
{
$rij2 = ' ';
}
else
{
$rij2 = mysql_fetch_object($result2);
}
}
编辑:纠正第一个中的条件,如果
,因为@andrewsi发现 - =
是一个赋值运算符,所以以前你的代码正在将 $ voornaam
更改为 NULL
,然后检查结果是否评估为 true
(当然,它永远不会 - 所以第二个块将始终执行)
Corrected your condition in the first if
, as @andrewsi spotted - =
is an assignment operator, so previously your code was changing $voornaam
to NULL
, then checking if the result evaluated to true
(which, of course, it never would - so the second block would always execute)
在您的原始代码中,您使用的是和
运算符 - 可能已经看到它用于一些很好的意义但编码不好的示例,例如 mysql_connect (...)或死亡('发生错误');
。
In your original code, you're using the and
operator - presumably having seen it used in some well meaning but poorly coded examples like mysql_connect(...) or die('an error occurred');
.
该示例中发生的事情是第一个结果声明 - mysql_connect()
- 已选中。如果计算结果为true,则第二个语句永远不会执行,但如果计算结果为false,则执行第二个语句 - die('发生错误');
- 。正如您刚刚发现的那样,这种模式令人困惑,最好避免使用。
What's happening in that example is that the result of the first statement - mysql_connect()
- is checked. If it evaluates to true, the second statement never executes, but if it evaluates to false then the second statement - die('an error occurred');
- is executed. As you've just discovered, this pattern is confusing and best avoided.