1

I have the following code that I would like to use to add check boxes to the interface depending on the selected drop down value

    <!--drop down list for the floors--> 
<div class="form-group">
    <label for="ddlFloorNo"><?php echo $_data['add_new_form_field_text_10']; ?> :</label>
    <select onchange="getUnitReport(this.value)" name="ddlFloorNo" id="ddlFloorNo" class="form-control">
        <option value="">--<?php echo $_data['add_new_form_field_text_11']; ?>--</option>
        <?php
        $result_floor = mysqli_query($link, "SELECT * FROM tbl_add_floor order by fid ASC");
        while ($row_floor = mysqli_fetch_array($result_floor)) {
            ?>
            <option <?php
            if ($floor_id == $row_floor['fid']) {
                echo 'selected';
            }
            ?> value="<?php echo $row_floor['fid']; ?>">
                <?php echo $row_floor['floor_no']; ?></option>
        <?php } ?>
    </select>
</div>
 <!--Check boxes to be displayed based on the selected floor inn the drop down list above--> 
    <div class="form-group">
        <label for="ChkOwnerUnit"><?php echo $_data['add_new_form_field_text_8']; ?> : </label>
        <?php
        $result_unit = mysqli_query($link, "SELECT * FROM tbl_add_unit where floor_no ='" . (int) $row_floor['fid'] . "' order by uid ASC");
        while ($row_unit = mysqli_fetch_array($result_unit)) {
            ?>
        <input type="checkbox" class="form-control" name="ChkOwnerUnit[]" value="<?php echo $row_unit['uid']; ?>"/>
            <?php } ?>
    </div>

My problem is that the checkboxes do not show up. What could I be doing wrong

6
  • Are you sure there is data in that table with a floor_no matching the fid you are passing Commented Sep 12, 2018 at 9:38
  • How exactly did you determine that they don't show up? What have you tried to debug the problem? Commented Sep 12, 2018 at 9:38
  • Did you check the page source using your browser to see if there is anything there, but it is just not showing up due to some HTML issue Commented Sep 12, 2018 at 9:40
  • @RiggsFolly yes there is data Commented Sep 12, 2018 at 9:44
  • @NicoHaase they are not visible Commented Sep 12, 2018 at 9:45

1 Answer 1

3

Its because you are not getting data in your line

$result_unit = mysqli_query($link, "SELECT * FROM tbl_add_unit where floor_no ='" . (int) $row_floor['fid'] . "' order by uid ASC");

$row_floor is not accessible at there. You need to make changes in either html or create array to store ids.

Sign up to request clarification or add additional context in comments.

6 Comments

I did the same thing with option select but it worked would you give me a clue on how to go about making it work? I am new with php
you are trying to use that $row_floor variable out of the while loop so, you do not have data in (int) $row_floor['fid'], thus query will not return any thing and checkboxes are not showing
the $row_floor is in the dropdown menu
yes and you are using the ids (int) $row_floor['fid'] from that variable for getting checkbox values, but these ids are not accessible there in another query. Please create an array to store the ids and use that array. if that is dependent data then you should go for AJAX call
Would you proovide me with a link to some tutorial on the ajax?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.