abrahamgarcia27 Posted August 26, 2011 Share Posted August 26, 2011 (edited) 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 March 18, 2016 by requinix password removed by request Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/ Share on other sites More sharing options...
MasterACE14 Posted August 26, 2011 Share Posted August 26, 2011 there is no $rows. Is it suppose to be? $results['status'] Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262099 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262164 Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262166 Share on other sites More sharing options...
Psycho Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262167 Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262184 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 but you agree that 0 means false ? what if false was the "desired" outcome? you wouldn't use a 1 for false.... Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262186 Share on other sites More sharing options...
Muddy_Funster Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262195 Share on other sites More sharing options...
WebStyles Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262197 Share on other sites More sharing options...
Psycho Posted August 26, 2011 Share Posted August 26, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245726-updating-a-tiny-int/#findComment-1262200 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.