0

I am using MySQL Database under which I have a table named sponsors having following columns.

id | project_id | project_name | sector | duration | budget | location  

Now, I have created a page in php on which a user can select multiple projects at a time by clicking on the checkbox as you can see in the image below :

Multiple projects selection page

After selecting the projects, when user clicks on submit, a pop-up form will appear like this :

Pop-up form

On which there should be the comma separated values of project_id (from the Database) of all the selected projects by user.

So far I've done this much coding :

 <!-- //CheckBOX -->
 <td> <input type="checkbox" name="check_id[]"
                            value="<?php $row["project_id"];?>"> </td>
 <td> <?php echo $data["project_id"]; ?>   </td>
 <td> <?php echo $data["project_name"]; ?> </td>

See this to have a view of full code.

So, my question is How to fetch column values from database onto a Pop-up form for only those projects that have been checkbox selected by user ?

How can I achieve that. I am open to accept any sensible solution in any language, but would prefer to have it in JavaScript or php .

1
  • Question, do you have it?
    – u_mulder
    Commented Apr 12, 2018 at 18:37

1 Answer 1

0

I am going to assume that you are adding the table-rows with a loop of some sort, and if so, you can assign the value of the key in your checkboxes name field, then use that on the other end to pull the matching $data[] value;

<?php foreach ($yourArray as $key => $data): ?>
<!-- //CheckBOX -->
 <td> <input type="checkbox" name="check_id[<?php echo $key; ?>]"
                            value="YES"> </td>
 <td> <?php echo $data["project_id"]; ?>   </td>
 <td> <?php echo $data["project_name"]; ?> </td>
<?php endforeach; ?>

Then when the form is submitted you pull the key back and use it to retrieve the value in your original array. It would look something like this:

foreach ($_POST['check_id'] as $key => $value) {
    if ($value == 'YES') {
        $selectedRows[] = $yourArray[$key];
    }
}

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.