简体   繁体   English

根据从MYSQL返回的查询值选中一个复选框

[英]Check a checkbox based on a query value returned from MYSQL

i have a checkbox in a form that is unchecked and i run a query in php to update the form i need the checkbox to be checked when MYSQL value is 1 and unchecked for any other value (usually 0 but could be NULL) i have run the query and can place the value into a text field and this was to make sure i was returning something and yes it is either 1 or 0. hoping all i need is a simple if statement but have yet been unable to create one that works. 我有一个处于未选中状态的复选框,并且在php中运行了一个查询以更新该窗体,当MYSQL值为1且未选中任何其他值(通常为0,但可能为NULL)时,我需要选中该复选框查询并可以将值放入文本字​​段中,这是为了确保我返回的是是1或0。希望我所需要的只是一个简单的if语句,但仍无法创建有效的语句。

i have run a query that is called $query6 and this returns all the values needed for the form and i am calling values like so $rows['MaxxeBasic'] being the column name in the mysql table. 我已经运行了一个名为$ query6的查询,它返回了表单所需的所有值,并且我正在调用类似$ rows ['MaxxeBasic']这样的值,这是mysql表中的列名。

the code below is an input that is checked but should change based on the return from the $query6 for the $rows['MaxxeBasic'] 以下代码是经过检查的输入,但应基于$ rows ['MaxxeBasic']的$ query6返回值进行更改

    <input type="checkbox" class="form-checkbox" id="input_9_0" name="q9_sitePackage[]" value="' . $rows['MaxxeBasic'] . '" checked="checked"   />

The following line of code show a list of some the additional checkboxes i will need to deal with however once i have managed the first one the others should be straight forward. 下面的代码行显示了一些我需要处理的其他复选框的列表,但是,一旦我管理了第一个复选框,其他复选框就应该很简单。

    echo '<li class="form-line" id="id_9">
    <label class="form-label-left" id="label_9" for="input_9"> Site Package </label>
    <div id="cid_9" class="form-input">
      <div class="form-single-column"><span class="form-checkbox-item" style="clear:left;">



          <input type="checkbox" class="form-checkbox" id="input_9_0" name="q9_sitePackage[]" value="' . $rows['MaxxeBasic'] . '" checked="checked"   />
          <input class="form-textbox form-address-city" type="text" name="q5_address5[city]" id="input_5_city" size="21" value="' . $rows['MaxxeBasic'] . '"/>
          <label for="input_9_0"> Maxxe-Basic </label></span><span class="clearfix"></span><span class="form-checkbox-item" style="clear:left;">
          <input type="checkbox" class="form-checkbox" id="input_9_1" name="q9_sitePackage[]" value="' . $rows['MaxxeStd'] . '" />
          <label for="input_9_1"> Maxxe-Basic Plus </label></span><span class="clearfix"></span><span class="form-checkbox-item" style="clear:left;">
          <input type="checkbox" class="form-checkbox" id="input_9_2" name="q9_sitePackage[]" value="' . $rows['MaxxeMore'] . '" />
          <label for="input_9_2"> Maxxe-Std </label></span><span class="clearfix"></span><span class="form-checkbox-item" style="clear:left;">
          <input type="checkbox" class="form-checkbox" id="input_9_3" name="q9_sitePackage[]" value="' . $rows['MaxxeBasicPlus'] . '" />
          <label for="input_9_3"> Maxxe-Std Plus </label></span><span class="clearfix"></span><span class="form-checkbox-item" style="clear:left;">
          <input type="checkbox" class="form-checkbox" id="input_9_4" name="q9_sitePackage[]" value="' . $rows['MaxxeStdPlus'] . '" />
          <label for="input_9_4"> Maxxe-More </label></span><span class="clearfix"></span><span class="form-checkbox-item" style="clear:left;">
          <input type="checkbox" class="form-checkbox" id="input_9_5" name="q9_sitePackage[]" value="' . $rows['MaxxeMorePlus'] . '" />
          <label for="input_9_5"> Maxxe-More Plus </label></span><span class="clearfix"></span>
      </div>
    </div>
  </li>';

尝试这个:

<input type="checkbox" class="form-checkbox" id="input_9_0" name="q9_sitePackage[]" value="' . $rows['MaxxeBasic'] . '"'. ($rows['MaxxeBasic'] == 1 ? ' checked="checked"' : '').'   />

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

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