问题
I am new to mySQL and I am fetching several data from a DB and throwing it over a table like this:
// Create connection
$connection = new mysqli( $servername, $username, $password, $dbname );
//test if connection failed
if ( mysqli_connect_errno() ) {
die( "Error: "
. mysqli_connect_error()
. " (" . mysqli_connect_errno()
. ")" );
}
//get results from database
$result = mysqli_query( $connection, "SELECT * FROM SentEmails" );
$all_property = array(); //declare an array for saving property
//showing property
echo '<table class="data-table">
<tr class="data-heading">'; //initialize table tag
while ( $property = mysqli_fetch_field( $result ) ) {
echo '<td>' . $property->name . '/td>'; //get field name for header
array_push( $all_property, $property->name ); //save those to array
}
echo '</tr>'; //end tr tag
//showing all data
while ( $row = mysqli_fetch_array( $result ) ) {
echo "<tr>";
foreach ( $all_property as $item ) {
echo '<td>' . $row[ $item ] . '</td>'; //get items using property value
}
echo '</tr>';
}
echo "</table>";
However some of the columns are boolean. I would like to display a "✓" or a "✖" in the appropriate column, instead of "1" or "0". Is this possible, without breaking down the SELECT or mounting the table over several steps? Perhaps a javascript function after the table is ready? Thank you.
来源:https://stackoverflow.com/questions/62765660/check-if-a-mysql-query-has-boolean-values-and-display-or