Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/246.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何修复php中的语法错误、意外的T_IF错误?嵌入在php中的html_Php - Fatal编程技术网

如何修复php中的语法错误、意外的T_IF错误?嵌入在php中的html

如何修复php中的语法错误、意外的T_IF错误?嵌入在php中的html,php,Php,我想把if-else放在变量类型中,然后它会显示下面的html代码,但它会显示语法错误的错误,在php中显示意外的T_if错误 $data .='<tr> <td>'.$number.'</td> <td>'.$EventName.'</td> <td>'.$Type.'</td>

我想把if-else放在变量类型中,然后它会显示下面的html代码,但它会显示语法错误的错误,在php中显示意外的T_if错误

            $data .='<tr>
                <td>'.$number.'</td>
                <td>'.$EventName.'</td>
                <td>'.$Type.'</td>
                <td>'.$Gender.'</td>
                <td>'.$RegistrationFee.'</td>
                <td>'.$EntryLimit.'</td>
                <td>'.$Rating.'</td>'
                .if ($Type=="Singles"){.'
                <td>
                    <button onclick="JoinTournament('.$row['Tournament_EventID'].')" class="btn btn-danger">Join</button>
                </td>'
                .}.
                '</tr>';
            $number++;
        }
    } else {
        $data .= '<tr><td colspan="9" style="text-align:center">No records found</td></tr>';
    }

    $data .='</table>';


    echo $data;

    }

不能将if语句放入字符串串联中。尝试此修复程序:

$data .='<tr>
    <td>'.$number.'</td>
    <td>'.$EventName.'</td>
    <td>'.$Type.'</td>
    <td>'.$Gender.'</td>
    <td>'.$RegistrationFee.'</td>
    <td>'.$EntryLimit.'</td>
    <td>'.$Rating.'</td>';

if ($Type=="Singles") {
    $data .= '<td>
        <button onclick="JoinTournament('.
        $row['Tournament_EventID'].
        ')" class="btn btn-danger">Join</button>
    </td>';
}

$data .= '</tr>';

谢谢!这起作用了
$Join ="";
        if($Type=="Singles")
        {
            $Join = '<button onclick="JoinTournament('.$row['Tournament_EventID'].')" class="btn btn-danger">Join</button>';
        }
              $data .='<tr>
                            <td>'.$number.'</td>
                            <td>'.$EventName.'</td>
                            <td>'.$Type.'</td>
                            <td>'.$Gender.'</td>
                            <td>'.$RegistrationFee.'</td>
                            <td>'.$EntryLimit.'</td>
                            <td>'.$Rating.'</td>
                            <td>'.$Join.'</td>
                        </tr>';
                $number++;