Jump to content

Updating a Tiny Int


abrahamgarcia27

Recommended Posts

I am trying to update a tiny int i have the if statement which says when tiny int is 1 echo closed and when tiny int 0 echo open. The problem is i am trying to query the result in a drop down but the option of status Closed doesnt appear.

 

 

<?php
//connect to database
$con=mysql_connect("localhost","root","")
or die("couldn't connect to mysql");
//select database
$db=mysql_select_db("ac_res",$con)
or die("database not found");
//get ID to Edit
$id = $_GET['id'];
//Query Fields to edit
$sql = 'SELECT * FROM `ac_reservation` WHERE `id` = "'.$id.'"';
  $query = mysql_query($sql) or die("Couldn't execute query. ". mysql_error());
  $results = mysql_fetch_array($query);
  $status = 'status';
//Query the waiter table
$waiter=mysql_query("SELECT fname FROM waiter")
or die("query error");
 

?>

<form id="edituser" name="edituser" method="post" action="editresexec.php">
  <table width="300" border="0" align="center" cellpadding="2" cellspacing="0">
  <tr>
      <th> </th>
      <td><input name="id" type="hidden" class="textfield"  value= <?php echo $results[id]?> /> </td>
    </tr>
    <tr>
      <th>First Name </th>
      <td><input name="fl_name" id="keyboard2" type="text" class="textfield"  value= <?php echo $results[fl_name]?> /> </td>
    </tr>
    <tr>
      <th>Number of People</th>
      <td><input name="n_people" id="keyboard3" type="text" class="textfield"  value= <?php echo $results[n_people]?> /> </td>
    </tr>
    <tr>
      <th>Table Number</th>
      <td><input id="t_number"name="t_number" type="text" class="textfield"  value= <?php echo $results[t_number]?> /></td>
    </tr>
    <tr>
        <th>Waiter</th>
      <td><?php echo "<select name=waiter>";
while($r=mysql_fetch_array($waiter))
{
//echo waiter name
echo "<option value='".$r['fname']."'>".$r['fname']."</option>";
}
echo "</select>";
?>
    </td>
    </tr>
    <tr>
      <th>Status</th>
      <td><?php
  //If statement
  if($rows['status'] == 1) {
$status = "Close";
} else
$status = "Open";
  //Drop Down Menu For Status
echo "<select>";
echo "<option value='".$status."'>".$status."</option>";

echo "</select>";
?>  </td>
    </tr>
    <tr>
        <td> </td>
      <td><input type="submit" name="Update" value="Update" /></td>
    </tr>
  </table> 
</form>
Edited by requinix
password removed by request
Link to comment
Share on other sites

when tiny int is 1 echo closed and when tiny int 0 echo open

 

 

This has obviously no impact, and as long as you remember your own logic everything will always work, but I just thought I would mention that when using Booleans (value 1 or 0), the "normal" logic is that 0 is false, closed, inactive, no, negative, etc... and 1 is true, open, active, yes, positive, ...

 

You seem to be using the inverse: 1 for closed, 0 for open.

Link to comment
Share on other sites

when tiny int is 1 echo closed and when tiny int 0 echo open

 

 

This has obviously no impact, and as long as you remember your own logic everything will always work, but I just thought I would mention that when using Booleans (value 1 or 0), the "normal" logic is that 0 is false, closed, inactive, no, negative, etc... and 1 is true, open, active, yes, positive, ...

 

You seem to be using the inverse: 1 for closed, 0 for open.

That really depends on the context of the output.  If "closed" is the desired value, or the result of a successfull operation then 1 would be more applicable.

Link to comment
Share on other sites

when tiny int is 1 echo closed and when tiny int 0 echo open

 

 

This has obviously no impact, and as long as you remember your own logic everything will always work, but I just thought I would mention that when using Booleans (value 1 or 0), the "normal" logic is that 0 is false, closed, inactive, no, negative, etc... and 1 is true, open, active, yes, positive, ...

 

You seem to be using the inverse: 1 for closed, 0 for open.

That really depends on the context of the output.  If "closed" is the desired value, or the result of a successfull operation then 1 would be more applicable.

 

"Desired value", what's that have to do with it? Booleans are logical values that have specific meanings. I agree with WebStyles on this one. A '0' for closed makes much more sense.

Link to comment
Share on other sites

Because if a status of "closed" is actualy a positive (desired) value in the context of the program then it would clearly be more logical to have it set to boolean 1.  without knowing what the overall obgectives are you can't apply a generalisation of positive and negative outcomes to the values used.

 

If I want to check a car before it drives away and see if the doors are open or closed I would clearly use 1 to represent closed because that would be the desired positive status to progress with the final action.

Link to comment
Share on other sites

well no, because to reitterate the car scenario the question would then need to be "are the doors open - true or false" which is obviously just daft.  Tt would be, if anything "are the doors closed - true or false" maintaining the consistancy.  I'm not arguing the logical assignment of boolean values, just saying that sometimes overall context is relevent to what is used.

Link to comment
Share on other sites

well no, because to reitterate the car scenario the question would then need to be "are the doors open - true or false" which is obviously just daft.  Tt would be, if anything "are the doors closed - true or false" maintaining the consistancy.  I'm not arguing the logical assignment of boolean values, just saying that sometimes overall context is relevent to what is used.

 

I know what you mean, and I confess I've also used it the other way round in some cases. But I have also had problems because of that. I manage a lot of different systems, some of them built over 10 years ago, and I always have to go and check if 1 meant good/bad, etc... If I had used the same rule from the start, 15 years ago, for everything, it would have saved me a lot of time... That's why I though I would mention it.

Link to comment
Share on other sites

If I want to check a car before it drives away and see if the doors are open or closed I would clearly use 1 to represent closed because that would be the desired positive status to progress with the final action.

 

But, that is not how the OP is using "closed". Closed is not the field with a 1 representing that the doors are closed (true). He is using a boolean for the field "status" and then the logic in the code uses a TRUE value for "status" to represent "Close" and a FALSE "status" value to represent "Open". I'll concede that there could possibly be a logical justification for that. but, I'd be willing to bet that is not the case here.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.