Отображение 0/1 как нет/да из MYSQL с PHP

У меня есть таблица mysql со строкой, которая либо будет 0, либо 1. Однако я хочу иметь возможность отображать таблицу с PHP и показывать 0 как нет, и 1 отображается как "да". Я все еще новичок в PHP и искал способ сделать это, но не повезло. Строка, о которой идет речь, - это строка "мастерская работа". Строка кода, которую я думал, будет делать это

$row['masterwork'] = ( intval( $row['masterwork']) == 1)? "YES": "NO";

Вот код, который отображает таблицу:

<!--?php
$con=mysqli_connect("localhost","username","password","database");
// Check connection
if (mysqli_connect_errno())
 {
 echo "Failed to connect to MySQL: " . mysqli_connect_error();
 }

$result = mysqli_query($con,"SELECT * FROM weapons");

$row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";

while($row = mysqli_fetch_array($result))
 {
 echo "<center-->";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 }
echo "<table border="1"><tbody><tr><td>Weapon Name: </td><td>" . $row['weaponName'] . "</td></tr><tr><td>Creator: </td><td>" . $row['creator'] . "</td></tr><tr><td>Weapon Category: </td><td>" . $row['weaponCategory'] . "</td></tr><tr><td>Weapon Sub-Category: </td><td>" . $row['weaponSubCategory'] . "</td></tr><tr><td>Cost: </td><td>" . $row['costAmount'] . " " . $row['costType'] . "</td></tr><tr><td>Damage(S): </td><td>" . $row['damageS'] . "</td></tr><tr><td>Damage(M): </td><td>" . $row['damageM'] . "</td></tr><tr><td>Critical: </td><td>" . $row['critical'] . "</td></tr><tr><td>Range Increment: </td><td>" . $row['rangeIncrement'] . "</td></tr><tr><td>Weight: </td><td>" . $row['weight'] . "</td></tr><tr><td>Weapon Type: </td><td>" . $row['weaponType'] . "</td></tr><tr><td>Masterwork: </td><td>" . $row['masterwork'] . "</td></tr><tr><td>Special Abilities: </td><td>" . $row['specialAbilities'] . "</td></tr><tr><td>Additional Info: </td><td>" . $row['additionalInfo'] . "</td></tr></tbody></table>";
echo "";

mysqli_close($con);
?>
1 ответ

попробуй это --

$result = mysqli_query($con,"SELECT * FROM weapons");



while($row = mysqli_fetch_array($result))
 {
 $row['masterwork'] = ( intval( $row['masterwork']) == 1) ? "YES" : "NO";
 echo "<center>";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 echo "";
 }
echo "<table border="1"><tbody><tr><td>Weapon Name: </td><td>" . $row['weaponName'] . "</td></tr><tr><td>Creator: </td><td>" . $row['creator'] . "</td></tr><tr><td>Weapon Category: </td><td>" . $row['weaponCategory'] . "</td></tr><tr><td>Weapon Sub-Category: </td><td>" . $row['weaponSubCategory'] . "</td></tr><tr><td>Cost: </td><td>" . $row['costAmount'] . " " . $row['costType'] . "</td></tr><tr><td>Damage(S): </td><td>" . $row['damageS'] . "</td></tr><tr><td>Damage(M): </td><td>" . $row['damageM'] . "</td></tr><tr><td>Critical: </td><td>" . $row['critical'] . "</td></tr><tr><td>Range Increment: </td><td>" . $row['rangeIncrement'] . "</td></tr><tr><td>Weight: </td><td>" . $row['weight'] . "</td></tr><tr><td>Weapon Type: </td><td>" . $row['weaponType'] . "</td></tr><tr><td>Masterwork: </td><td>" . $row['masterwork'] . "</td></tr><tr><td>Special Abilities: </td><td>" . $row['specialAbilities'] . "</td></tr><tr><td>Additional Info: </td><td>" . $row['additionalInfo'] . "</td></tr></tbody></table>";
echo "</center>";

mysqli_close($con);
?>

licensed under cc by-sa 3.0 with attribution.