Reputation: 140
I need to display the string values in HTML table based on the int value fetched from mySQL database. it is a checking process of users prime member or not.
My HTML Code is
<table class="table table-bordered">
<thead>
<tr>
<th>Store Name</th>
<th class="text-center" style="width: 10%;"> Prime </th>
</tr>
</thead>
<tbody>
<?php
while($eachitem = $result->fetch_assoc())
{
?>
<tr>
<td> <?php echo remove_junk($eachitem['name']); ?></td>
<td class="text-center"> <?php echo remove_junk($eachitem['prime']); ?></td>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
And I have my db configuration in config.php
<?php
include('config.php');
// SQL query to select data from database
$sql = "SELECT * FROM store ";
$result = $con->query($sql);
?>
The HTML code for adding prime to database is
<select name="prime" class="form-control">
<option value="0">Not prime</option>
<option value="1">prime</option>
</select>
I have Int values 0 and 1 in store table row names prime. Now i need to show No instead on 0 and Yes instead of 1 without changing drop down values in HTML
Upvotes: 1
Views: 632
Reputation: 5301
use the ternary operator ?
(a.k.a. conditional operator). It has the form
(condition) ? (what to do if condition is true) : (what to do if condition is false);
For your code, change
<?php echo remove_junk($eachitem['prime']); ?>
to
<?php echo remove_junk($eachitem['prime']) ? 'Yes' : 'No'; ?>
Upvotes: 1