模态

时间:2017-11-03 05:19:32

标签: php html mysql

如果我点击表格中的查看按钮,它应该打开一个模态表格        显示所有表值以查看它。但我得到的错误是未定义的        位于文本框内的变量位置,我只调用位置        在table.kindly帮助我如何从dbs获取数据作为PHP        code.thanks提前。 更新:我已经更新了我的代码。请检查出来,因为我调用了ajax,但模态框打开时为空,没有信息加载。坚持帮助它。



<!-- Main content -->
	<div class="main-content">
		<h1 class="page-title">OUR POP DETAILS</h1>
		<!-- Breadcrumb -->
		<ol class="breadcrumb breadcrumb-2"> 
			<li><a href="index.html"><i class="fa fa-home"></i>Home</a></li> 
			<li><a href="basic-tables.html">Metro Pop</a></li> 
			<li class="active"><strong>Action</strong></li> 
		</ol>
		
			<div class="row">
      <div class="col-md-12"></div>
     
      <div class="col-md-4">
        <?php $apage = array('id'=>'','name'=>'');?>
        <script>var page_0 = <?php echo json_encode($apage)?></script>
        <h3><a data="page_0" class="model_form btn btn-sm btn-danger" href="#"><span class="glyphicon glyphicon-plus"></span> Add new record</a></h3>
      </div>
  </div>
		
		<div id="table-container">
			 <div class="row">
    
      <div class="col-md-12">
           <table id="table" class="table table-striped table-sortable table-condensed  " cellspacing="0" width="100%"
		   
		   
                           data-show-columns="true"
                           >
                        
		   
		   
		   
		   
		   
		   
		   

	
		   
            <tbody>
			
                <?php if(isset($result) && ($data_record) > 0)  : $i=1; ?>
                    <?php  while ($users = mysqli_fetch_object($result)) { ?>
					

                        <tr class="<?=$users->id?>_del">
						
                            <td><?=$i;?></td>
                            <td><?=$users->zonee;?></td>
                            <td><?=$users->location;?></td>
                            <td><?=$users->pop_type;?></td>
                            <td><?=$users->switch_name;?></td>
							  <td><?=$users->switch_ip;?></td>
							  <td><?=$users->switch_make;?></td>
							  <td><?=$users->switch_serial;?></td>
							  <td><?=$users->switch_model;?></td>
                           
                            <td> <a href="http://maps.google.com/?q=<?=$users->latitude;?>,<?=$users->longitude;?>" target=\"_blank\"><i class="material-icons">&#xE0C8;</i></a></td>
							
                            <script>var page_<?php echo $users->id ?> = <?php echo json_encode($users);?></script>
							
                            <td><a data="<?php echo 'page_'.$users->id ?>" class="model_form btn btn-info btn-sm" href="#"> <span class="glyphicon glyphicon-pencil"></span></a>
							
                            <a data="<?php echo  $users->id ?>" title="Delete <?php echo $users->name;?>" class="tip delete_check btn btn-info btn-sm "><span class="glyphicon glyphicon-remove"></span> </a>  
     
						   
							 <button data-toggle="modal" data-target="#view-modal"  data-id="<?php echo $users->id; ?>"  class=" view_check  btn btn-sm btn-info"><i class="glyphicon glyphicon-eye-open"></i></button>
							</td>
                        </tr>
                <?php $i++; 
				} ?>
            <?php else : echo '<tr><td colspan="8"><div align="center">-------No record found -----</div></td></tr>'; ?>
           <?php endif; ?>               
            </tbody>
        </table>
          <?php
              if(isset($_SESSION['flash_msg'])) :  
               $message = $_SESSION['flash_msg'];
               echo $error= '<div class="alert alert-success" role="alert">
               <span class="glyphicon glyphicon-envelope"></span> <strong>'.$message.'</strong> </div>';
               unset($_SESSION['flash_msg']);
              endif;
          ?>


         

         
</div>
      </div>
     
  </div> 
		
    
    
    
     
<div id="view-modal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" style="display: none;">
   <div class="modal-dialog"> 
      <div class="modal-content"> 
                  
         <div class="modal-header"> 
             <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button> 
             <h4 class="modal-title">
             <i class="glyphicon glyphicon-user"></i> POP Information
             </h4> 
         </div> 
        
         <div class="modal-body" id="employee_detail"> 
                                       
            
                             
         </div> 
		
           
       <div class="modal-footer"> 
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>  
       </div>  
              
      </div> 
   </div>
</div>











<!-- Form modal -->
  <div id="form_modal" class="modal fade" tabindex="-1" role="dialog">
    <div class="modal-dialog modal-md">
      <div class="modal-content">
        <div class="modal-header">
          <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
          <h4 class="modal-title"><i class="icon-paragraph-justify2"></i><span id="pop_title">ADD</span> POP INFORMATION</h4>
        </div>
        <!-- Form inside modal -->
        <form method="post" action="add_edit.php" id="cat_form">
          <div class="modal-body with-padding">
            <div class="form-group">
              <div class="row">
			  
			  
			  
                <div class="col-sm-12">
                  <label>zonee :</label>
                   <input type="text" name="zonee" id="zonee"  class="form-control required">
                </div>
              </div>
            </div>
            <div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>location :</label>
                   <input type="text" name="location" id="location" class="form-control required">
                </div>
              </div>
            </div>
           
            <div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>pop_type :</label>
                   <input type="text" name="pop_type" id="pop_type" class="form-control required number">
                </div>
              </div>
            </div>
            <div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>switch_name:</label>
				    <input type="text" name="switch_name" id="switch_name" class="form-control required number">
                   
                </div>
              </div>
            </div>
            <div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>switch_ip :</label>
                   <input type="text"  name="switch_ip" id="switch_ip" class="form-control required" >
                </div>
              </div>
            </div>
			<div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>switch_make :</label>
				    <input type="text"  name="switch_make" id="switch_make" class="form-control required" >
                   
                </div>
              </div>
            </div>
			<div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>switch_serial :</label>
				  <input type="text"  name="switch_serial" id="switch_serial" class="form-control required" >
                   
                </div>
              </div>
            </div>
			<div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>switch_model :</label>
				   <input type="text"  name="switch_model" id="switch_model" class="form-control required" >
                 
                </div>
              </div>
            </div>
			
			<div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>Latitude:</label>
				   <input type="text"  name="latitude" id="latitude" class="form-control required" >
                 
                </div>
              </div>
            </div>
			
			<div class="form-group">
              <div class="row">
                <div class="col-sm-12">
                  <label>Longitude:</label>
				   <input type="text"  name="longitude" id="longitude" class="form-control required" >
                 
                </div>
              </div>
            </div>
			
			
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-warning" data-dismiss="modal">Cancel</button>
            <span id="add">
              <input type="hidden" name="id" value="" id="id">
              <button type="submit" name="form_data" class="btn btn-primary">Submit</button>
            </span>
          </div>
        </form>
      </div>
    </div>
  </div>
<!-- /form modal -->



    
    
    
&#13;
&#13;
&#13;

&#13;
&#13;
<script type="text/javascript">
$(document).ready(function() {
    $(document).on('click','.model_form',function(){
        $('#form_modal').modal({
          keyboard: false,
          show:true,
          backdrop:'static'
        });
        var data = eval($(this).attr('data'));
        $('#id').val(data.id);
		  $('#zonee').val(data.zonee);
        $('#location').val(data.location);
        $('#pop_type').val(data.pop_type);
        $('#switch_name').val(data.switch_name);
        $('#switch_ip').val(data.switch_ip);
        $('#switch_make').val(data.switch_make);
        $('#switch_serial').val(data.switch_serial);
		 $('#switch_model').val(data.switch_model);
		 $('#latitude').val(data.latitude);
		 $('#longitude').val(data.longitude);
        if(data.id!="")
            $('#pop_title').html('Edit');
		
        else 
            $('#pop_title').html('Add');
			
       
    });  
    $(document).on('click','.delete_check',function(){
      if(confirm("Are you sure to delete data")){
        var current_element = $(this);
        url = "add_edit.php";
        $.ajax({
        type:"POST",
        url: url,
        data: {ct_id:$(current_element).attr('data')},
        success: function(data) { //location.reload(); 
          $('.'+$(current_element).attr('data')+'_del').animate({ backgroundColor: "#003" }, "slow").animate({ opacity: "hide" }, "slow");
        } 
      });
      }
     });     
	 
	 
	 
	 $(document).on('click', '.view_check', function(){
  //$('#dataModal').modal();
  var employee_id = $(this).attr("id");
  $.ajax({
   url:"view.php",
   method:"POST",
   data:{employee_id:employee_id},
   success:function(data){
    $('#employee_detail').html(data);
    $('#view-modal').modal('show');
   }
  });
 });
});  
	 
	 
	 
});
</script>

 

 
&#13;
&#13;
&#13;

&#13;
&#13;
**view.php**

<?php  
 
    include("config.php");
if(isset($_POST["employee_id"]))
{
 $output = '';
 $connect = mysqli_connect("localhost", "root", "", "mine");
 $query = "SELECT * FROM user WHERE id = '".$_POST["employee_id"]."'";
 $result = mysqli_query($connect, $query);
 $output .= '  
      <div class="table-responsive">  
           <table class="table table-bordered">';
    while($row = mysqli_fetch_object($result))
    {
     $output .= '
     <tr>  
            <td width="30%"><label>Name</label></td>  
            <td width="70%">'.$users["location"].'</td>  
        </tr>
        <tr>  
            <td width="30%"><label>Address</label></td>  
            <td width="70%">'.$users["zonee"].'</td>  
        </tr>
        <tr>  
            <td width="30%"><label>Gender</label></td>  
            <td width="70%">'.$users["pop_type"].'</td>  
        </tr>
        
        
     ';
    }
    $output .= '</table></div>';
    echo $output;
}
?>
&#13;
&#13;
&#13;

4 个答案:

答案 0 :(得分:0)

添加配额(&#39;&#39;),例如$ row [&#39; location&#39;],您正在使用$ row [location]

或使用以下代码

<div class="col-sm-12">
          <label>location :</label>
          <input type="text" name="location" id="location" value="<?php 
          echo $row['location'];?>" />

        </div>

答案 1 :(得分:0)

您的变量名称为$users而不是$row,因此您可以写这个

 <div class="form-group">
      <div class="row">
        <div class="col-sm-12">
          <label>location :</label>
          <input type="text" name="location" id="location" value="<?php 
          echo $users['location'];?>" />

        </div>

答案 2 :(得分:0)

试用此代码

   <tbody>

        <?php if(isset($result) && ($data_record) > 0)  : $i=1; ?>
            <?php  while ($users = mysqli_fetch_object($result)) { ?>


                <tr class="<?=$users->id?>_del">

                    <td><?=$i;?></td>
                    <td><?=$users->zonee;?></td>
                    <td><?=$users->location;?></td>
                    <td><?=$users->pop_type;?></td>
                    <td><?=$users->switch_name;?></td>
                      <td><?=$users->switch_ip;?></td>
                      <td><?=$users->switch_make;?></td>
                      <td><?=$users->switch_serial;?></td>
                      <td><?=$users->switch_model;?></td>

                    <td> <a href="http://maps.google.com/?q=<?=$users-
           >latitude;?>,<?=$users->longitude;?>" target=\"_blank\"><i 
        class="material-icons">&#xE0C8;</i></a></td>

                    <script>var page_<?php echo $users->id ?> = <?php 
       echo json_encode($users);?></script>

                    <td><a data="<?php echo 'page_'.$users->id ?>" 
     class="model_form btn btn-info btn-sm" href="#"> <span 
    class="glyphicon glyphicon-pencil"></span></a>

                    <a data="<?php echo  $users->id ?>" title="Delete <?
         php echo $users->name;?>" class="tip delete_check btn btn-info 
   btn-sm "><span 
         class="glyphicon glyphicon-remove"></span> </a>  

                     <button data-toggle="modal" data-target="#view-
            modal" data-id="<?php echo $users->id; ?>" id="getUser" 
                   class="btn btn-sm 
               btn-info"><i class="glyphicon glyphicon-eye-open"></i>
                </button>
                    </td>
                </tr>
        <?php $i++; 
        echo "<div class='modal-body'> 

     <div id='dynamic-content'> 
     <div class='form-group'>
      <div class='row'>
        <div class='col-sm-12'>
          <label>location :</label>
          <input type='text' name='location' id='location' value='$users->location' />

        </div>




      </div>
    </div>


     </div> 

 </div> "
    } ?>
    <?php else : echo '<tr><td colspan="8"><div align="center">-------No 
      record found -----</div></td></tr>'; ?>
   <?php endif; ?>               
    </tbody>

答案 3 :(得分:-1)

点击通话功能

<script>
      function launch_modal(id)
      {
        //Store id in variable
        var newId = id;
        //Ajax Start
         $.ajax({
          type: "POST",
          url: "your_php_page.php",
          //send id to php page
          data: {theId:newId},
          success: function(data){
            //to display data in paragraph of Modal
            $('.modal-body').html(data);
            //to display modal
            $('#myModal').modal("show");
          },
        });
      }
</script>

your_php_page.php

<?php
    $theId = $_POST['theId'];
    if($theId){

        $output = '';
        $sql = $conn->query("select * from table where id = '$theId'");
        $fetch = $sql->fetch_object();
        //Append
        $output .= '<table class="table table-bordered">
                    <tr>
                        <td>Name :</td>
                        <td>'.$fetch->name.'</td>
                    </tr>
                    <tr>
                        <td>Number :</td>
                        <td>'.$fetch->number.'</td>
                    </tr>
                    ';
        echo $output;
    }
?>