PHP从gridview编辑行

My php functions runs a query and displays the data in a grid. I have attached a button the user is to click if they want to edit a particular row. The data of that row is being called from the database table called mytable, and the main column is pk_tId.

I'm trying to figure out how to pull the row that was clicked and display the row data in a bootstrap modal window.

All of this code is in one file called edit.php. I will try to figure out how to chop it up and put in different files to include later, but for the meanwhile, everything is in this one file.

In the edit.php file, I have the database connection being included near the top of the page. I really hope you don't need to see that. Just know that I have a steady connection to the database.

I was asked before to show all of the code, so here we go...starting with the php function:

 <?php
 function displayrecords(){
   $groups = $_POST['mygroup'];
   $type = $_POST['mytype'];
   $service = $_POST['myservice'];
   $sql_json = "SELECT * FROM mytable";
   $where = "";
   if ($groups != ""){
       $where = " `mygroup` = '".mysql_real_escape_string($groups)."'";
     }
   if($type != ""){
     if( $where != "" ) $where .= " AND ";
     $where .= " `mytype` = '".mysql_real_escape_string($type)."'";
   }
   if($service != ""){  
     if( $where != "" ) $where .= " AND ";
     $where .= " `myservice` = '".mysql_real_escape_string($service)."'";
   }
   if ($where != "") $sql_json = $sql_json . " WHERE " . $where . " AND delete_flag = 'N';";
   $QueryResult = @mysql_query($sql_json) or die (mysql_error());
     echo "<table class='table table-striped table-bordered table-hover'>
";
     echo "<tr><th>Delete/Edit</th>" . "<th>Group</th><th>Type</th>" . "<th>Service</th>" . "<th>Description</th></tr>
";
     while(($Row = mysql_fetch_assoc($QueryResult)) !== FALSE) {
     echo "<tr><td><a class=\"modalInput btn btn-primary btn-mini\" data-toggle=\"modal\" href=\"#myEditModal?". $Row['pk_tId'] ."\" \">Delete/Edit</a></td>";
     echo "<td>{$Row[mygroup]}</td>";
     echo "<td>{$Row[mytype]}</td>";
     echo "<td>{$Row[myservice]}</td>";
     echo "<td>{$Row[mydescription]}</td></tr>
";
     };
     echo "</table>
";
     if (mysql_num_rows($QueryResult) == 0){
       echo "No results";
     }
 }
 ?>

Sorry if that was a lot of code, but it was suggested to me that I include all of the code. Here is where I have added the Edit button in the php code. I'm thinking this is where it all begins:

 echo "<tr><td><a class=\"modalInput btn btn-primary btn-mini\" data-toggle=\"modal\" href=\"#myEditModal?". $Row['pk_tId'] ."\" \">Delete/Edit</a></td>";

Here is the modal window where the row data needs to be pulled into:

 <div class="modal hide fade" id="myEditModal" tabindex="-1" role="dialog" aria-labelleby="myModalLabel" aria-hidden="true">
    <form class="well-small" action="edit.php" method="POST" id="modalForm" name="modalForm">
       <input type="text" id="group" name="group" value="<?php echo $selection[mygroup]; ?>" />
       <input type="text" id="type" name="type" value="<?php echo $selection[mytype]; ?>" /> 
       <input type="text" id="service" name="service" value="<?php echo $selection[myservice]; ?>" /> 
       <textarea rows="4" cols="20" id="description" name="description" value="<?php echo $selection[mydescription]; ?>"></textarea> 
       <input type="submit" id="modal-form-submit" name="submit" class="btn btn-primary" href="#" value="Update" />
       <input type="submit" id="modal-form-submit" name="submit" class="btn btn-primary" href="#" value="Delete" /> 
    </form>
 </div>

I know I need a javascript function, so I tried to use this at the top of the edit.php page inside the header tags:

 <script type="application/javascript">
   $(".modalInput").on("click", function(e) {
   var detailURL;
   e.preventDefault();
   detailURL = $(this).attr("href");
   $('#myEditModal').load(detailURL, function(){
   });
   });
 </script>

I'm sure the javascript code needs some work.

To all my fellow Web Developers, I need your help. I need to get this application completed, and this is probably the last piece of code I need to get working. Please disregard any typos, missing brackets, or un-matching variables. The code works except for being able to load the data into the modal window.

Also, I know I could use ajax, but for the time being, I just need to utilize php, javascript, and mysql.

Thank you in advance.

Your right a lot of code and I am note sure I absorbed it all, but did you create a div with an id of myEditModal? I cannot see one.

Also there are 2 .load functions in jQuery and the one called depends upon the parameters you give the function call. I think you may have the wrong set of parameters for the .load you intended to run.