Home > Software engineering >  How does div affect passing parameters to php?
How does div affect passing parameters to php?

Time:10-23

I have a table showing information from database and everything works good. In next step i want to get the id of an exact row and pass it to edit function, in which the name will be changed only. The problem comes most probably from the the modal. When i tried printing the id, (see the picture) in case 1 it prints correctly 1,2,3, etc. But in case 2 it gives always only '1'. So my question is why and how div affect this?

Solution, found with the help of @Abdel Rahman Yosry.

<button  value="lecture" data-toggle='modal' data-target='#editModal_<?php echo $row[' lec_id ']?>'><i ></i></button>
<div class='modal fade' id='editModal_<?php echo $row[' lec_id ']?>' tabindex='-1' role='dialog' aria-labelledby='editModalLabel'>
  <div class='modal-dialog' role='document'>
    <div class='modal-content'>
      <div class='modal-header'>
        <button type='button' class='close' data-dismiss='modal' aria-label='Close'><span aria-hidden='true'>&times;</span></button>
        <h4 class='modal-title' id='editModalLabel'>Edit Lecture's Name </h4>
      </div>
      <div class='modal-body'>
        <form method='post' action='<?=rootDirectory?>admin'>
          <div class='form-group'>
            <label for='lec_name' class='control-label'>Lecture Name:</label>
            <input type='text' class='form-control lec_name' id='lec_name' name='lec_name'>
          </div>
          <div class='modal-footer'>
            <button type='button' class='btn btn-primary' data-dismiss='modal'>Close</button>
            <input class='btn btn-primary' name='editLecture' type='submit' value='Add'>
            <input type="hidden" value='<?=$row[' lec_id ']?>' name="lec_id" />
          </div>
        </form>
      </div>
    </div>
  </div>
</div>

Added id='editModal_<?php echo $row[' lec_id ']?>' for every row to has its specific modal and also the hidden input to grab the lec_id.

CodePudding user response:

you can <div class='modal fade' id='editModal_<?php echo $row['lec_id']?>' tabindex='-1' role='dialog' aria-labelledby='editModalLabel'> in this way you will have container for every element in database with editModal_[id of your element] and you can access it and do whatever you want.

  • Related