Check if a MySQL query has boolean values and display ✓ or ✖

谁说我不能喝 提交于 2020-07-10 06:27:50

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!