how to hide 1 table after click on to submit button

<?php include 'dbConfig.php';
 session_start();
?>
<html lang="en">
<head>
<title>Import CSV file</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
<link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
  .msg-reports-table>tbody>tr>th{
    background:#ffc3c2;
}
 .selcls{ 
    padding: 6px; 
    border: solid 1px #517B97; 
    outline: 0; 
    background: -webkit-gradient(linear, left top, left 25, from(#FFFFFF), color-stop(4%, #CAD9E3), to(#FFFFFF)); 
    background: -moz-linear-gradient(top, #FFFFFF, #CAD9E3 1px, #FFFFFF 25px); 
    box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px; 
    -moz-box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px; 
    -webkit-box-shadow: rgba(0,0,0, 0.1) 0px 0px 8px; 

    } 
</style>
</head>
<form name="frmdropdown" method="post" action="">
        
          
       
     <center>
            <h4 align="center">Log Report</h4>
         
            <strong> Select Batch: </strong> 
            <select class=" selcls input-sm" name="Batch"  data-style="btn-success"> 
               <option value=""> -----------ALL----------- </option> 
            <?php
  
                 $res=mysqli_query($db,"Select DISTINCT batch_id from log");
                 while($r=mysqli_fetch_row($res))
                 { 
                       echo "<option value='$r[0]'> $r[0] </option>";
                 }
             ?>
              </select>
        <input type="submit" name="find" value="Report" id="find" class="btn btn-primary btn-sm" onclick="submit()" /> 
       <a href="exportData.php" class="btn btn-success btn-sm" id="export" name="export">Export Data</a>
     <br><br>
<?php
 $batch1 = $_SESSION['ex2'];  
 ?>
  <div class="table">
           
 <table class="table table-bordered table-striped msg-reports-table" id="table" display="">
 <tr>
     <th>Batch Id </th>      <th>Status</th>     <th>Phone</th>    <th>Message</th>    
 </tr> 
 <?php
 $res=mysqli_query($db,"Select * from log where remark like '%success%'and batch_id='".$batch1."'");
    echo "<tr><td colspan='5'></td></tr>";
          
                          while($row = mysqli_fetch_array($res))  
                          {  
                               echo '  
                               <tr>  
                                    <td>'.$row["batch_id"].'</td>  
                                    <td>'.$row["remark"].'</td>  
                                    <td>'.$row["phone"].'</td>  
                                    <td>'.$row["query_string"].'</td>  
                                     
                               </tr>  
                               ';  
                          }  
  ?>
  </table>
 </div>

 <?php
  if($_SERVER['REQUEST_METHOD'] == "POST")
  {
    ?>

     <table class="table table-bordered table-striped msg-reports-table" id="table1">
 <tr>
     <th>Batch Id </th>      <th>Status</th>     <th>Phone</th>    <th>Message</th>    
 </tr> 
 <?php 

         $batch=$_POST["Batch"]; 
        
         $_SESSION['ex1'] = $batch;
         // $batch1 = $_SESSION['ex2'];  
      
         if($batch=="")  // if ALL is selected in Dropdown box
         { 
             $res=mysqli_query($db,"Select * from log");
        //  $res=mysqli_query($db,"Select l.batch_id,case when l.remark like '%Success%' then 'Sent' else 'Pending' end status,l.phone,t.message from log l,to_numbers t");
        
         }
         else
         { 
             $res=mysqli_query($db,"Select * from log where remark like '%success%'and batch_id='".$batch."'");
         }
  
         echo "<tr><td colspan='5'></td></tr>";
          
                          while($row = mysqli_fetch_array($res))  
                          {  
                               echo '  
                               <tr>  
                                    <td>'.$row["batch_id"].'</td>  
                                    <td>'.$row["remark"].'</td>  
                                    <td>'.$row["phone"].'</td>  
                                    <td>'.$row["query_string"].'</td>  
                                     
                               </tr>  
                               ';  
                          }  
                          
    }
?>
  </table>
 </center>
</form>
<!-- <script type="text/javascript">
$(document).ready(function()
{
    $("#table").show();
    $("#find").click(function()
    {
        $("#table").hide();
    });
});
</script> -->
 <script type="text/javascript">
function submit() {

    //$("input[id=find]:submit").click(function () {
        //if ($('input[id=opt]:checked').val() == "y") {
            $('.table').hide();
          }
   // });
//});
</script>
</body>

</html>

Open in new window



this is my code here i have two tables i need hide above table after clicking submit button please let me know how to do
shruti AAsked:
Who is Participating?
 
Chris StanyonCommented:
Easiest way is to check if you have the POST 'find' key set (your submit button) and if you do, hide the table. You can do this a couple of ways. You can either 'hide' the table using CSS (display:none) or you could skip over the entire <table> code so that it never gets generated in your HMTL. To hide using CSS, edit line 55 in your code to something like this:

<div class="table" style="display: <?php echo isset($_POST['find']) ? "none" : "block" ?>">

Open in new window

This will set the display to none if POST['find'] is set, otherwise it will set it to display as a block.

If you want to skip the generation of the table altogether, wrap the whole <div class="table"> block in an if statement:

<?php if (!isset($_POST['find'])); ?>
<div class="table">
    <table class="table table-bordered table-striped msg-reports-table" id="table" display="">
    ...
    </table>
</div>
<?php endif; ?>

Open in new window

Now if the 'find' key doesn't exist in the POST array, then you know the form hasn't been submitted, and that block of HTML will be generated. If you do have the 'find' key, the whole block will be skipped.
2
 
shruti AAuthor Commented:
K thnq i 'll try this code
0
 
shruti AAuthor Commented:
tq bro, tq so much .....
0
 
shruti AAuthor Commented:
worked fine
0
 
Chris StanyonCommented:
Cool
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.