<?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表:
嗨!
Bonusz(tinyint(1))的值为0和1.我想将“nem”表示为0,将“igen”表示为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>';
}
}
?>