1

I would like to put if else in the variable "type" then it will display the following html code below but it displays the error of syntax error, unexpected T_IF error in php

            $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;

    }
Robert Deml
  • 12,390
  • 20
  • 65
  • 92

2 Answers2

0

You cannot put an if statement inside a string concatenation. Try this fix:

$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>';
sensorario
  • 20,262
  • 30
  • 97
  • 159
-1
$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++;
Subhash Shipu
  • 343
  • 1
  • 4
  • 15