PHP - MySql - >如果Bonus值1写入Text

时间:2016-03-24 11:15:09

标签: php mysql

<?php
  $conn->query("SET NAMES 'utf8'");
  $sql = mysqli_query($conn, "SELECT * FROM kategoria");
  if (mysqli_num_rows($sql) > 0) {
    while ($row = mysqli_fetch_assoc($sql)) {
      if ($row['bonusz'] == 1) {
        $bonusz = "Igen";
      } else {
        $bonusz = "Nem";
      }
      echo '<tr><td>' . $row['Kategoria_ID'] . '</td><td>' . $row['Ertek'] . ' Ft.</td><td>' . $bonusz . '</td></tr>';
    }
  }
  ?>

MySQL表:

MySQL Table (picture)

嗨!

Bonusz(tinyint(1))的值为0和1.我想将“nem”表示为0,将“igen”表示为1。

1 个答案:

答案 0 :(得分:0)

尝试将“bonusz”更改为“Bonusz”

 <?php
  $conn->query("SET NAMES 'utf8'");
  $sql = mysqli_query($conn, "SELECT * FROM kategoria");
  if (mysqli_num_rows($sql) > 0) {
    while ($row = mysqli_fetch_assoc($sql)) {
       if ($row['Bonusz'] == 1) {
         $bonusz = "Igen";
       } else {
        $bonusz = "Nem";
       }
  echo '<tr><td>' . $row['Kategoria_ID'] . '</td><td>' . $row['Ertek'] . ' Ft.</td><td>' . $bonusz . '</td></tr>';
}
 }
 ?>