开发者

Retrieving from Tinyint and converting to text in html

开发者 https://www.devze.com 2023-03-31 23:16 出处:网络
I have a form that sets attributes for a product via checkbox. The form sends the checkbox to the database, and the database stores it as 0 or 1. If 0, the attribute does not exist fo开发者_JAVA技巧r

I have a form that sets attributes for a product via checkbox. The form sends the checkbox to the database, and the database stores it as 0 or 1. If 0, the attribute does not exist fo开发者_JAVA技巧r the product, if 1, it exists. I want some of these to display the attribute name, instead of a "1" or a "0". For example, If it is horizontal oriented, I want it to display "Horizontal".

I am now trying to select these results from the database and display them on my table. Here is the code from my table.

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>";
?>

How can I do this? My insertpage looks like

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)

?>


Try this

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>

or something like it.

0

精彩评论

暂无评论...
验证码 换一张
取 消