-1

with table i fetch data in tabular format and with each row there is add button.

<a href="#"  data-id="<?php echo $row[0];?>" name="pppid"  class="btn btn-primary filter" data-toggle="modal" data-target="#myModal1" name="">ADD</a>

it will open modal now i want only each rows data in modal.

<div  class="modal fade" id="myModal1" role="dialog">
<div class="modal-dialog">
    <div class="modal-content">
        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>             
        </div>
        <div class="modal-body">            
            <table id="name52" class="table table-striped table-bordered table-hover scroll" style="width:100%;">
                <thead>
                   <tr>
                   <th>Project Name</th>
                   <th>Module Name</th>
                   <th>Actual Start Date</th>
                   <th>Actual End Date</th>               
                   <th>Status</th>                 
                   </tr> 
                </thead>         
                <tbody>                                     
                <?php
                $fetch =$_REQUEST['pppid']; 
                $sql1=mysql_query("select * from `project_assigned` where `proj_ass_id`='$fetch'");
                while ( $row1 = mysql_fetch_array($sql1))
                 {?>
                 <tr>
                    <input required type='hidden' class='insert' value="<?php echo $row1[0]?>">                                
                    <td><?php echo get_name("add_project","project_id",$row1['project_id'],"project_name");?><input id="project_id" type="text" class="insert" value="<?php echo $row1['project_id'];?>"></td>
                    <td><?php echo get_name("add_project_module","module_id",$row1['module_id'],"module_name");?><input id="module_id" type="text" class="insert" value="<?php echo $row1['module_id'];?>"></td></td>
                    <input class="insert" type="hidden" name="" value="<?php echo $row1['emp_id'];?>">
                    <td><input class="controls input-group date insert" type="text" name=""></td>
                    <td><input class="controls input-group date insert" type="text" name=""></td>
                    <td><select class="insert">
                         <option value="In Progress">In Progress</option>
                         <option value="Completed">Completed</option>
                    </select></td>                                          
                 </tr>
                 <?php  }?>                                         
                 </tbody>
            </table>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-primary submit">Submit</button>
        </div>
    </div>   
</div>
</div>

when i use this code with $fetch variable that i declare in anchor tag it will not display that particular row. As this request is not working for me I used another way to call ajax on ajax page i write query and script to fetch records but its also not working. my ajax page is working it shows data but below script for this is not working.

 <script>
            $('.filter').click(function(){
              var id = $(this).data('id');
              alert(id);
              $.ajax({url:"modal_emp_status.php"+id,cache:false,success:function(result){                
                alert(var str = result.split(","));
                alert($("#project_id").val(str[0]));
                alert($("#module_id").val(str[1]));

              }});
            });         
 </script>

my ajax page working:

<?php
include('config.php');
$sql = mysql_query("select * from `project_assigned` where `proj_ass_id`='1'");
$data = mysql_fetch_array($sql);
$str = $data['project_id'].",".$data['module_id'];
echo $str;
?>

for reference

in image you can see add button. on click add button modal will open but i want only particular row to display in modal.

mahadev sutar
  • 171
  • 2
  • 16
  • A little off topic here: I see your code uses the mysql extension of PHP which since version 5.5 is deprecated http://php.net/manual/en/migration55.deprecated.php – Webbanditten Mar 25 '17 at 11:38
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[a Kitten is strangled somewhere in the world](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly Mar 25 '17 at 11:44
  • For each row you should create an individual modal. Each "Add" button referring to a model with unique id. In your case i can see you just have one modal with id "myModal1". Or you can have one modal, but on each click you update the contents via javascript according to your requirements. – f_i Mar 25 '17 at 11:51
  • @Faiz99 i want to update content with javascript but its not working for me – mahadev sutar Mar 25 '17 at 12:04
  • 1
    Your code is hard to understand, from what i know your anchors which invoke the filter class actions should be inside the loop so that they get all individual rows id's. Lets say you achieve that, then your ajax call is not sending the id properly.. lets say you achieve that as well. you are not querying your database with id on every call, you have passed a static id in your query. – f_i Mar 25 '17 at 15:31

1 Answers1

-1

Where is your class='filter' that your jquery $('.filter') referring to? It can't be found anywhere in your html.

BTW, please read this article, mysql extension has been deprecated since php5.5.

hcheung
  • 3,377
  • 3
  • 11
  • 23