Reputation: 859
I am trying to not show some elements in a form depending on the number of rows froud from the query. But problem is that it is outputting some of the if statement and not hiding the form.
Below is an if statement to display a message if no rows are found:
if($sessionnum ==0){
$pHTML = "<span style='color: red'>Sorry, You There No Assessments under this Module</span>";
}
The above is fine but below is the problem where I am trying to only show something in the form if the a row is found from the query:
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p id='warnings'>{$pHTML}</p>
{$outputmodule}
if($sessionnum !=0){
<p><strong>Assessments:</strong> {$sessionHTML} </p>
}
</form>
</div>";
echo $assessmentform;
Upvotes: 0
Views: 48
Reputation: 32790
You can not write condition in side a string.
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p id='warnings'>{$pHTML}</p>
{$outputmodule}";
if($sessionnum !=0){
$assessmentform = ."<p><strong>Assessments:</strong> {$sessionHTML} </p>";
}
$assessmentform = ."
</form>
</div>";
echo $assessmentform;
Upvotes: 1
Reputation: 1419
If you want to hide the form, place the condition above the form.
if($sessionnum !=0){
$assessmentform = "<div id='lt-container'>
<form action='".htmlentities($_SERVER['PHP_SELF'])."' method='post' id='assessmentForm'>
<p id='warnings'>{$pHTML}</p>
{$outputmodule}
<p><strong>Assessments:</strong> {$sessionHTML} </p>
</form>
</div>";
echo $assessmentform;
}
Upvotes: 1