-4

When I click edit, 'id' should pass to own page and modal should pop up. But it doesn't work. Please help me

PHP and Bootstrap

<tr>        
    <td><?php echo $row['name']; ?></td>   
    <td><a data-toggle="modal" data-target="#myModal" href='?id=<?php echo $row['id']; ?>'>Edit</a> </td>          
</tr>

Modal

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
         ------
         -----
         -----
    </div>
</div>
Greg Pettit
  • 10,749
  • 5
  • 53
  • 72
  • `href="?id="` variables don't get parsed in single quotes *for one thing*. – Funk Forty Niner Dec 18 '15 at 16:34
  • you need javascript to toggle modals. http://getbootstrap.com/javascript/#modals - also don't mix PHP and HTML code that way, better create templates and load them via PHP – messerbill Dec 18 '15 at 16:35
  • Plus, `?id` implies a GET method, so we have no idea how you're fetching that array. – Funk Forty Niner Dec 18 '15 at 16:36
  • 2
    Possible duplicate of [How to pass $\_GET variables from a link to a bootstrapmodual?](http://stackoverflow.com/questions/32433765/how-to-pass-get-variables-from-a-link-to-a-bootstrapmodual) – Shehary Dec 18 '15 at 17:22

1 Answers1

1

Create a class Edit in <a></a> tag. Use this class to call modal. And, add data-Id="<?echo $row['id'];?>"

<tr>        
    <td><?php echo $row['name']; ?></td>   
    <td>
        <a class='Edit' data-toggle="modal" href="#form_modal" data-target="#myModal" data-Id="<?php echo $row['id'];?>">Edit</a>
    </td>          
</tr>

Place this code in footer

<div id="myModal" class="modal fade" role="dialog">
    <div class="modal-dialog modal-lg">
        <div class="modal-content">

        </div>
    </div>
</div>

JS

<script>
$('.Edit').click(function(){
    var Id=$(this).attr('data-Id');
    $.ajax({url:"SomePage.php?Id="+Id,cache:false,success:function(result){
        $(".modal-content").html(result);
    }});
});
</script>

Create somepage.php (If you want to change this page name. Change in <script></script> too. Both are related.)

SomePage.php

<?php
$Id=$_GET['Id'];
?>

<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
    <h4 class="modal-title" id="fam_id"></h4>
</div>
<div class="modal-body">
    <?php echo $Id;?>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>

For more info, click Show data based of selected id on modal popup

Community
  • 1
  • 1
Nana Partykar
  • 10,556
  • 10
  • 48
  • 77
  • thank you. but model is pop up window. So, how can i pass the value to existing window? for example, There is a field called "Name", and edit button. If I Press edit button, I need the name as a editable format. So I should pass the id which can take name from database. –  Dec 18 '15 at 17:49
  • Yess. `Id` is passed in ``. Use that `$Id` to fetch name from DB Table. Put name in editable format. @Nishakar – Nana Partykar Dec 18 '15 at 17:51
  • And, please let me know what happened there @Nishakar – Nana Partykar Dec 18 '15 at 18:02
  • Wow its working, thank you so much, really thank you. May i have your fb id plz? And you forgot to put " –  Dec 18 '15 at 18:21
  • It's good. That working. But, why i opt this way is when we have 2-3 modal in one project. Then, it will be very handy to use a single modal. Why to create a separate modal for each purpose. Because, i faced some issue 1 year back for having 10-12 modal for each and every purpose. So, i suggest all people to do this way only. *Sorry, I am not in facebook* . **If you think this answer helped you, please tick this as correct answer. As, it will help other user to find it easily.** *Enjoy Coding* @Nishakar – Nana Partykar Dec 18 '15 at 18:27
  • http://stackoverflow.com/questions/34388408/bootstrap-in-data-table-master-doesnt-refresh?noredirect=1#comment56518929_34388408 @nana . do you know how to solve this problem –  Dec 21 '15 at 06:03
  • Sorry @Nishakar. I don't know the solution of this question. – Nana Partykar Dec 21 '15 at 11:40
  • Actually i couldn't understand that return part of success $.ajax({url:"SomePage.php?Id="+Id,cache:false,success:function(result){ $(".modal-content").html(result); }}); Here if this is successful, then something is returned from SomePage.php. What would it return? Normally i do understand that it will return only 'echo' part of php. But in that SomePage.php , there are no php function, only it has got html, but it returns html.. I want to know how this return part works? could you please explain me, or show me a reference book? plz –  Dec 21 '15 at 18:01