从Tinyint中检索并转换为html中的文本

时间:2011-09-01 01:42:40

标签: php mysql

我有一个表单,通过复选框设置产品的属性。表单将复选框发送到数据库,数据库将其存储为0或1.如果为0,则该产品的属性不存在,如果为1,则存在该属性。我希望其中一些显示属性名称,而不是“1”或“0”。例如,如果它是水平方向的,我希望它显示“水平”。

我现在正尝试从数据库中选择这些结果并将其显示在我的表格中。这是我桌上的代码。

include 'connect.php';
$result = mysql_query ("SELECT * FROM inventory"); 

echo "Inventory";
echo "<table border='1' id='listings1table'>";
echo "<tr><th colspan='6'>inventory list</th></tr>";
echo "<tr><td>ID #</td><td>Size</td><td>Material</td><td>Orientation</td><td>Has Photo</td><td>Manage</td></tr>";


while ($row = mysql_fetch_array($result))
{

echo "<tr><td>" . $row[id] . "</td><td>" . $row['size'] . " " . "Gallons" . "</td><td>" . $row['material'] . "</td>";
echo "<td>" . $row['horizontal'] . "</td><td> No </td>";
echo "<td><a href='deleteitem.php?id=" . $row['id'] . "'>Delete</a></td></tr>";
echo "<br />";
}
echo "</table>";
?>

我该怎么做?我的插页看起来像

include 'connect.php';

$horizontal = isset($_POST['horizontal']) ? 1 : 0;

 $sql="INSERT INTO inventory (horizontal, vertical) VALUES (''$horizontal', '$vertical')"; 

  if (!mysql_query($sql,$con))
  {
  die ('Error : ' . mysql_error());
  }
  echo "<br /><br /><center><font size='5' face='Arial' color='green'>1 record added</font></center>";
  echo '<meta http-equiv="refresh" content="2; index.php" />';

  mysql_close($con)

?>

1 个答案:

答案 0 :(得分:1)

试试这个

while ($row = mysql_fetch_array($result)) : ?>
<tr>
    <td><?php echo $row['id'] ?></td>
    <td><?php echo $row['size'] ?> Gallons</td>
    <td><?php echo $row['material'] ?></td>
    <td><?php echo $row['horizontal'] == 1 ? 'Horizontal' : 'Not Horizontal?' ?></td>
    <td>No</td>
    <td><a href="deleteitem.php?id=<?php echo $row['id'] ?>">Delete</a></td>
</tr>
<?php endwhile ?>
</table>

或类似的东西。

相关问题