简体   繁体   English

如何在if语句中显示/比较mysql行的动态值?

[英]How do I display/compare a dynamic value of a mysql row in a if statement?

I have a checkboxes on my site that when unchecked, update their row in in the db as unchecked, and if checked,update their row in the db as checked. 我的网站上有一个复选框,当未选中时,将其在db中的行更新为未选中,如果选中,则将其在db中的行更新为选中。 I am creating an ifstatement that will commence with its command if checked, and not if unchecked. 我正在创建一个ifstatement,如果选中,它将以其命令开头,如果未选中,则不会。 I have echoed the variable and it is holding the proper value (checked or unchecked) but not sure if I am syntactically correct on displaying the state of the row in the db. 我已经回显了该变量,并且该变量持有正确的值(选中或未选中),但是不确定在语法上是否正确地显示了数据库中行的状态。

This is what I am trying and will not work. 这是我正在尝试的方法,将无法正常工作。 I am new at php still and thank you very much for any help. 我仍然是php新手,非常感谢您的帮助。

if($auth->check_prof == 'checked'){// do the stuff in here}


<input type="checkbox" name="auth" value="checked" />


<?php
if(isset($_POST['auth'])) {
    $auth->check_prof = 'checked'; // or $_POST['auth']
}

It might be a problem of confusing $auth->check_prof and $auth['check_prof'] . 可能是混淆$auth->check_prof$auth['check_prof']

Are you sure $auth is an object? 您确定$ auth是一个对象吗? If not, try if ($auth['check_prof'] == 'checked') . 如果没有,请尝试if ($auth['check_prof'] == 'checked')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM