重新加载表而不刷新整个页面在PHP中

时间:2017-12-22 11:32:30

标签: php html mysql

我从数据库中获取表中的数据,并且有三个按钮更新,删除和活动/非活动按钮,这三个按钮都有自己的功能,但事件发生后它必须重新加载更新后的数据表。我能够重新加载整个页面,但我只想重新加载表格内容,我对Javascript和ajax的了解较少..我没有得到正确的方法继续使用ajax ..请帮助我任何可以解决我的问题的程序..如何正确地集成到我的代码中。



<?php
session_start();
if(empty($_SESSION))
{
  header("Location: ../vendor/login.php");
}
$mpage = "printer";
$page = "list_printer.php";

include '../header.php';

?>
<!DOCTYPE html>
<html>


  <!-- Content Wrapper. Contains page content -->
  <div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
      <h1>
        Printer Lists
   
      </h1>
      <ol class="breadcrumb">
        <li><a href="#"><i class="fa fa-dashboard"></i> Home</a></li>
        <li><a href="#">Printer</a></li>
        <li class="active">List Printers</li>
      </ol>
    </section>

    <!-- Main content -->
    <section class="content">
      <div class="row">
        <div class="col-xs-12">
          

		  <?php
	 
	

	 //echo session_id();
	 $email1 = $_SESSION['email'];
	 $Vendor_id="SELECT Vendor_id FROM vendors where email = '$email1' ";
	$result=mysqli_query($conn,$Vendor_id);
	$row = mysqli_fetch_row($result);
 
						$sql = "SELECT Vendor_pricing_id, status, printer_name,process,material,color,strength,surface_finish,per_gram_charge,per_hour_charge FROM vendor_pricing where Vendors_Vendor_id= $row[0]";
						$query = mysqli_query($conn, $sql);
						if (!$query) {
							die ('SQL Error: ' . mysqli_error($conn));
						}
						
				
if(isset($_POST['submit'])) {
	$_SESSION['v_id']=$_POST['v_id'];
$update=$_POST['v_id'];
$p_gram=$_POST['p_gram'];
$p_hour=$_POST['p_hour'];


$qry=mysqli_query($conn,"UPDATE `vendor_pricing` SET `per_hour_charge`='$p_hour',`per_gram_charge`='$p_gram' WHERE `Vendor_pricing_id`='$update'");		

//echo "<meta http-equiv='refresh' content='0'>";
echo '<script type="text/javascript">';
  echo 'setTimeout(function () { swal("Updated!","Successfully!","success");';
  echo '}, 200);</script>';


//echo "<meta http-equiv='refresh' content='0'>";
  
}

if(isset($_POST['delete'])) {
	$update=$_POST['v_id'];
	mysqli_query($conn, "UPDATE vendor_pricing SET status = 'inactive' where Vendor_pricing_id=$update");
		echo "<meta http-equiv='refresh' content='0'>";
}	
if(isset($_POST['link'])) {
	$update=$_POST['v_id']; $st=$_POST['link'];

	if($st=="active")
	{ mysqli_query($conn, "UPDATE vendor_pricing SET status = 'inactive' where Vendor_pricing_id=$update");
echo "<meta http-equiv='refresh' content='0'>";}
	else { mysqli_query($conn, "UPDATE vendor_pricing SET status = 'active' where Vendor_pricing_id=$update"); 
	echo "<meta http-equiv='refresh' content='0'>";}
	
}					
			?>
		  
		  
          <div class="box table-responsive no-padding">
            <div class="box-header">
              <h3 class="box-title">List of all Printers</h3>
            </div>
            <!-- /.box-header -->
            <div id="response" class="box-body">
			
              <table id="example1" class="table table-bordered table-striped" >
                <thead>
                <tr>
                  <th>ID</th>
                                            <th width="10%">Printer Name</th>
                                            <th>Process</th>
											<th>Material</th>
                                            <th>Color</th>
                                            <th>Strength</th>
                                            <th>Surface Finish</th>
											<th padding>per Gram</th>
                                            <th>per Hour</th>
											<th >Action</th>
                </tr>
                </thead>
                <tbody>
                <?php
		
		while ($row = mysqli_fetch_array($query))
		{
			$vid=$row['Vendor_pricing_id'];
			$p_name=$row['printer_name'];
			$pro=$row['process'];
			$mat=$row['material'];
			$color=$row['color'];
			$type=$row['strength'];
			$sur=$row['surface_finish'];
			$p_gram=$row['per_gram_charge'];
			$p_hour=$row['per_hour_charge'];
			$st=$row['status']; if ($st=="active"){ $link='inactive';} 
						else { $link='active';}
		
										 
      	?>
				<tr>
					<form method="post">
					<td><?php echo $vid;?>
					<input type="hidden" value="<?php echo $vid;?>" name="v_id">
					</td>
					<td><?php echo $p_name;?></td>
					<td><?php echo $pro;?></td>
					<td><?php echo $mat;?></td>
					<td><?php echo $color;?></td>
					<td><?php echo $type;?></td>
					<td><?php echo $sur;?></td>
					<td style="padding:9px !important; margin:0px !important;" ><input type="text" style="background:none!important; width:45px; border:none !important; border-color:none;" value="<?php echo $p_gram;?>" name="p_gram"></td>
					<td style="padding:9px !important; margin:0px !important;"><input type="text" style="background:none!important; width:45px; border:none !important; border-color:none;"  value="<?php echo $p_hour;?>" name="p_hour"></td>
					<td>
                    
					<button type="submit" name="submit" value="submit" class="btn btn-info btn-small">Update</button>
					<button type="link" name="link" value="<?php echo $st;?>" class="btn btn-default btn-warning btn-small" style="color:white" ><?php echo $link;?></button>
                    <button type="delete" name="delete" value="delete" class="btn btn-default btn-warning btn-small" style="background:#ED5E68; color:white" >Delete</button>
					 
                    
					 </td>
					 
					</tr>
					 </form>	    
					<?php
		}
		
		?>
		
		
             
               
                </tbody>
               
              </table>
       </div>
            <!-- /.box-body -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->
 
<?php

include '../footer.php';

?>
</html>
&#13;
&#13;
&#13;

使用echo "<meta http-equiv='refresh' content='0'>";这行代码,我可以刷新整个页面,请帮助我如何只重新加载表

1 个答案:

答案 0 :(得分:1)

您无法使用服务器端脚本重新加载特定的html元素。

你需要研究可以完全按照自己的意愿行事的AJAX。