I have database table with fields id, text and type. And in type I can have values 1 and 2. I want to display one html output if returned type is 1, and other output if type is 2.
table:
id text type
1 Some text 1
2 Blah Blah 2
So my simple query SELECT * from table will return array of values. In my HTML I want to output it like this:
<?php foreach ($model as $data): ?>
<h4>Text where status is 1:</h4>
echo $data['text'];
<h4>Text where status is 2:</h4>
echo $data['text'];
<?php endforeach ?>
I have tried with using if inside foreach like this:
<?php if ($data['type'] == "1"): ?>
<h4>Text where status is 1:</h4>
echo $data['text'];
<?php else: ?>
<h4>Text where status is 2:</h4>
echo $data['text'];
<?php endif ?>
But this doesn't really work. Is my solution for this to have one query that will return text where type is 1, and another where type is 2 ? Or there is some better solution for this ?
I would like output like this:
<h4> Text where status is 1 </h4>
First text.
Second text.
Third text.
<h4> Text where status is 2 </h4>
Fourth Text.
Fifth Text.
$modelthe variable containing the SQL query result?