user1830984
user1830984

Reputation: 859

wanting to show something in form only if a query has a number of rows

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

Answers (2)

Prasanth Bendra
Prasanth Bendra

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

cartina
cartina

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

Related Questions