I have one table and in this table, I have two button Update and Disable I want to hide those buttons
I trying like this
<table id="example1" class="table table-bordered table-striped table-sm" style=" overflow: auto; ">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php
$hide = 'OFF';
if($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis){?>
<tr>
<td><?php echo $dis->disp_ch_no;?></td>
<td><?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?></td>
<td><?php echo $dis->from_branch_name;?></td>
<td><a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a></td>
<td><a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
</tr>
<?php }?>
</table>
this is my table
How can I hide these buttons
Try this,
<?php
$thswitch = 'OFF';
if($thswitch == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
whenever you want to show just $thswitch = 'ON'; it
You have to check the if () for each row as we did in th. Like:
<table id="example1" class="table table-bordered table-striped table-sm" style="overflow: auto;">
<tr>
<th>Dispatch Challan No</th>
<th>Date</th>
<th>From</th>
<?php $hide = 'OFF';
if ($hide == 'ON') { ?>
<th>Update</th>
<th>Delete</th>
<?php } ?>
</tr>
<?php foreach($dispatch as $dis) { ?>
<tr>
<td> <?php echo $dis->disp_ch_no;?> </td>
<td> <?php echo date("d-m-Y", strtotime($dis->disp_ch_date));?> </td>
<td> <?php echo $dis->from_branch_name;?> </td>
<?php if ($hide == 'ON') { ?>
<td>
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
<td>
<a class="btn btn-danger btn-sm" onclick="delete_dispatch('<?php echo $dis->disp_id; ?>');" title="Click here to delete your Dispatch record"><i class="fa fa-trash" style="color: #fff;"> Disable </i> </a>
</td>
<?php } ?>
</tr>
<?php } ?>
</table>
Or by using CSS you can hide this columns as:
Create a CSS class like:
.hidethisColumn { display: none !important; }
Use it in you table as:
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Update</th>
<th class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">Delete</th>
Similarly in rows inside foreach():
<td class="<?=(($hide == 'ON')? 'hidethisColumn' : '')?>">
<a class="btn btn-success btn-sm" href="<?php echo base_url(); ?>booking/dispatch_challan/DispatchChallanController/updateDispatchChallanPage?disp_id=<?php echo $dis->disp_id; ?>"><i class="fa fa-pencil" > Update</i></a>
</td>
Related
I'm creating a table using ajax and php but there's one problem, the table isn't showing in my div. I'm really new to ajax so I don't really fully understand it yet.
Here's my div:
<div class="body" id="live-data">
</div>
Here's the ajax code:
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#live_data').html(data);
}
});
}
fetch_data();
});
And here's fetch.php:
<?php
include('../global/db.php');
$output = '';
$sql ="SELECT * FROM students WHERE status = '0' AND stud_grade = '$level_id' ORDER BY date_enrolled DESC";
$result = mysqli_query($db, $sql);
$output .= '
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>';
if(mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)){
$output .= '
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
';
}
}
else {
$output .= '
<tr>
<td colspan="12">Data not Found</td>
</tr>';
}
$output .= '
</tbody>
</table>
</div>';
echo $output;
?>
It would great if anyone could help because I just don't know why it doesn't work
Edit:
I've changed the code so it returns the data in the console tab and here's what shows up:
<div class="table-responsive">
<table class="table table-bordered table-striped table-hover dataTable js-exportable">
<thead>
<tr>
<th width="135" class="noExport">Action</th>
<th width="90">LRN</th>
<th width="20">Level</th>
<th>Name</th>
<th width="20">Gender</th>
<th width="60">Type</th>
<th width="105" style="font-size: 14px!important;">Date Enrolled</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
<tr>
<td>
<button type="button" class="btn bg-cyan btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?>">
<i class="material-icons">search</i>
<span>Profile</span>
</button>
<button type="button" class="btn bg-orange btn-xs waves-effect" data-toggle="modal" data-target="#<?php echo $stud_id ?><?php echo $stud_id ?>">
<i class="material-icons">person</i>
<span>Parent</span>
</button>
</td>
<td><?php echo $stud_lrn ?></td>
<td><?php echo $stud_grade ?></td>
<td><?php echo $stud_lname ?>, <?php echo $stud_fname ?> <?php echo $stud_mname ?></td>
<td><?php echo $stud_gender ?></td>
<td><?php echo $stud_type ?></td>
<td style="font-size: 12px!important;"><?php echo $date_enrolled = date("M-d-Y g:i A", strtotime($date_enrolled));?></td>
</tr>
</tbody>
</table>
</div>
So it clearly returns the correct data but it just doesn't show up in the live-data div
Maybe take a look in your html where is your div. Your div id says "live-data" and in the ajax code you mentioned to fetch data for div id "#live_data" instead of "#live-data".
Maybe changing them for same name can solve your problem. I would use for thr div id and in the ajax same id names like "#liveData".
Example (same code, just edited to the right IDs, compare with your original):
Your HTML div
<div class="body" id="liveData">
</div>
Your ajax code
$(document).ready( function() {
function fetch_data() {
$.ajax({
url:"fetch.php",
method:"POST",
success:function(data){
$('#liveData').html(data);
}
});
}
fetch_data();
});
Just append the correct Id of the div tag in sucess function
I have a table of each request filed by the user with corresponding actions to it. When I click on the update button, it doesnt load the view after submitting it.
This is my html code:
<table id="dataTableRequestDrafts" class="table table-striped table-bordered data-table-drafts" style="width:100%">
<thead>
<tr>
<th style="display: none;">Request ID</th>
<th>Request Type</th>
<th>Date Requested</th>
<th>Date Last Updated</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach($param_drafts as $drafts){?>
<tr>
<td class="id" style="display: none;"><?php echo $drafts['idx']?></td>
<td class="type"><?php echo $drafts['request_type']?></td>
<td><?php echo $drafts['date_requested']?></td>
<td><?php echo $drafts['date_updated']?></td>
<td class="text-warning"><?php echo $drafts['status']?></td>
<td align="center">
<form action="<?php echo base_url('dashboard/staff/request/update_request_view'); ?>" method="post">
<input type="text" name="request_id" value="<?php echo $drafts['idx']?>" style="display: none;">
<button type="button" class="btn waves-effect waves-light btn-primary view-button"><i class="fa fa-eye"></i> View</button> <button type="submit" class="btn waves-effect waves-light btn-info update-button"><i class="fa fa-edit"></i> Update</button> <button type="button" class="btn waves-effect waves-light btn-danger delete-button" data-url="<?php echo base_url('dashboard/staff/request/delete');?>"><i class="fa fa-trash-o"></i> Delete</button>
</form>
</td>
</td>
</tr>
<?php } ?>
</tbody>
</table>
This is my function in the controller:
public function update_request_view()
{
$data = new stdClass;
$data->param_menu = 'request';
$idx = $this->input->post('request_id');
$type = $this->staffrequisition_model->getRequestType($idx);
$typeLower = strtolower($string = str_replace(' ', '', $type));
$commonContents = $this->staffrequisition_model->selectItem(array('idx'=> $idx));
$uncommonContents = json_decode($commonContents->contents);
$data->param_request = array_merge((array) $commonContents, (array) $uncommonContents);
$this->load->view('dashboard/staff/update_'.$typeLower.'_view', $data);
}
The view is seen in the response but it doesnt load the view. I was gonna use ajax but it would be tedious to load the data of the request in each input in the view and I want to return the whole html page not just a div.
Can you show the response here.
sometimes the response can't handle by browser. so it can't appear
From Here I am doing like I fetch data from database and display in table format still it is working fine, after I click the division_edit() function I want pass the value (id),how can do this.
<table id="dataTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $sql=m ysql_query( "SELECT * FROM division WHERE status !='1'"); for($i=1;$row=m ysql_fetch_assoc($sql);$i++){ ?>
<tr role="row" class="odd">
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $row[ 'division'];?>
</td>
<td><a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit()" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
<button class="btn btn-danger btn-xs" data-href="state_delete.php?id=<?php echo base64_encode($row['id']);?>"
data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash"></i> Delete</button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</tfoot>
</table>
May this help you:
<table id="dataTable" class="table table-bordered table-hover">
<thead>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php $sql=m ysql_query( "SELECT * FROM division WHERE status !='1'"); for($i=1;$row=m ysql_fetch_assoc($sql);$i++){ ?>
<tr role="row" class="odd">
<td>
<?php echo $i;?>
</td>
<td>
<?php echo $row[ 'division'];?>
</td>
<td><a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit(<?php echo $row['id']; ?>)" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
<button class="btn btn-danger btn-xs" data-href="state_delete.php?id=<?php echo base64_encode($row['id']);?>"
data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash"></i> Delete</button>
</td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th>S.No</th>
<th>Division</th>
<th>Action</th>
</tr>
</tfoot>
</table>
Try this..
<a class="btn btn-success btn-xs" href="state_edit.php?id=<?php echo base64_encode($row['id']);?>" onclick="division_edit(<?php echo $row['id'] ?>)" id="division_edit"><i class="fa fa-pencil-square-o"></i> Edit</a>
Screenshoot 1 contain all of my data on database table while screenshoot 2 is detail of someone data whenever i click on search icon on screenshoot 1.
What i need is, how to print only someone data without pass the ID/parameter on my url for calling the controller? Btw, im using DOMPDF as my pdf generator.
Here my code :
Model
public function view_kartu($kode_pasien)
{
$query = $this->db->query("SELECT * FROM tb_pasien where kode_pasien='$kode_pasien' LIMIT 1");
return $query->result_array();
}
Controller
public function cetakkartu($id) {
//set a value for $kode_pasien
$kode_pasien = $id;
// Load all views as normal
$data['title'] = "Data Pasien | Praktik Dokter Umum";
$data['kartu_pasien'] = $this->a_model->view_kartu($kode_pasien);
$this->load->view('cetak-kartu', $data);
// Get output html
$html = $this->output->get_output();
// Load library
$this->load->library('dompdf_gen');
// Convert to PDF
$this->dompdf->load_html($html);
$this->dompdf->render();
$this->dompdf->stream("cetak-kartu" . ".pdf", array ('Attachment' => 0));}
View for all data in my database table (screenshoot 1)
<div class="box">
<div class="box-body">
<div class="btn-group">
<a href="<?=base_url();?>index.php/a_controller/regismanual"/>
<button class="btn-success btn">
Tambah Pasien</button>
</a>
</div>
<br>
<br>
<div class="table-responsive">
<table id="rekam" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th>Kode Pasien</th>
<th>Nama Pasien</th>
<th>Email Pasien</th>
<th>Alamat Pasien</th>
<th>Tanggal Lahir</th>
<th>Umur</th>
<th>JK</th>
<th>No. Telp</th>
<th>Opsi</th>
</tr>
</thead>
<tr>
<tbody>
<?php
if(isset($pasien)){
$no=0; foreach ($pasien as $isi): $no++;
# code...
?>
<td><?php echo $isi->kode_pasien?></td>
<td><?php echo $isi->nama_pasien?></td>
<td><?php echo $isi->email_pasien?></td>
<td><?php echo $isi->alamat_pasien?></td>
<td><?php echo $isi->tanggal_lahir?></td>
<td><?php echo $isi->umur?></td>
<td><?php echo $isi->kode_jk?></td>
<td><?php echo $isi->no_telp?></td>
<td>
<a href="<?=base_url()?>index.php/a_controller/updatepasien/<?php echo $isi->kode_pasien?>">
<button type="button" class="btn-success btn"><span class="glyphicon glyphicon-pencil"></span></button>
</a>
<a href="<?=base_url()?>index.php/a_controller/deletepasien/<?php echo $isi->kode_pasien?>" onclick="return confirm('Apakah anda yakin akan menghapus data ini?')">
<button type="button" class="btn-inverse btn"><span class="glyphicon glyphicon-trash"></span></button>
</a>
<a href="<?=base_url()?>index.php/a_controller/detail/<?php echo $isi->kode_pasien?>">
<button type="button" class="btn-warning btn"><span class="glyphicon glyphicon-search"></span></button>
</a>
</td>
</tr>
</tbody>
<?php endforeach;}?>
</table>
</div>
View for my detail data (screenshoot 2)
<div class="box">
<div class="box-body">
<div class="btn-group">
<a href="<?php echo base_url("index.php/a_controller/cetakkartu/4");?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat</button>
</a>
</div>
<br>
<br>
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover">
<?php
if(isset($kartu)){
$no=0; foreach ($kartu as $isi): $no++;
# code...
?>
<tr>
<td>Kode Pasien</td>
<td><?php echo $isi->kode_pasien?></td>
</tr>
<tr>
<td>Nama Pasien</td>
<td><?php echo $isi->nama_pasien?></td>
</tr>
<tr>
<td>Email Pasien</td>
<td><?php echo $isi->email_pasien?></td>
</tr>
<tr>
<td>Alamat Pasien</td>
<td><?php echo $isi->alamat_pasien?></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td><?php echo $isi->tanggal_lahir?></td>
</tr>
<tr>
<td>Umur</td>
<td><?php echo $isi->umur?></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td><?php echo $isi->kode_jk?></td>
</tr>
<tr>
<td>No. Telp</td>
<td><?php echo $isi->no_telp?></td>
</tr>
<?php endforeach;}?>
</table>
</div>
</div>
</div>
Like you see, i need to pass someone ID like this
<a href="<?php echo base_url("index.php/a_controller/cetakkartu/4");?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat</button>
</a>
It will only print someone with ID = 4 , it makes me cant print others person detail data. Did i need to change the ID whenever i want to print someone data? It's really hard.
anyone can help me?
<a href="<?php echo base_url("index.php/a_controller/cetakkartu").$kartu[0]['kode_pasien'];?>"/>
<button class="btn-success btn">
Cetak Kartu Berobat
</button>
</a>
The following code is showing only the record list and i want when we click on a link then it go to another page which will suppose to show only the record details of a selected title. Currently, it always shows the same details. now what is the solution of show only the records details of a selected title
<table class="table table-striped table-bordered bootstrap-datatable datatable">// the record list table
<thead>
<tr>
<th>ID</th>
<th>Course Name</th>
<th>Duration</th>
<th>Subjects</th>
<th>Status</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
<?php $getcourseslist = find_all("select * from course");
while(#$getcourses = fetch_array($getcourseslist)){
?>
<tr>
<td><?= $getcourses->id; ?></td>
<td> <?= $getcourses->title;?></td>
<td><?= $getcourses->duration/12; ?> Years</td>
<td class="center">
<?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
while(#$getsubs = fetch_array($getsubjects)){
?>
<?= $getsubs->name; ?><br>
<?php } ?>
</td>
<td class="center">
<?php if($getcourses->status == 1){ ?>
<span class="label label-success">Active</span>
<?php }
else{
?>
<span class="label label-important">Blocked</span>
<?php } ?>
</td>
<td class="center">
<a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
<i class="halflings-icon white edit"></i>
</a>
<?php if($getcourses->status == 1){ ?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php }
else{
?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div><!--/span-->
</div><!--/row-->
// The following code is supposed to show only the record details of a selected title. Currently, it always shows the same detail list of previous page.//
Course Details View
<tr>
<th>ID :</th>
<td><?= $getcourses2->id; ?></td>
</tr>
<tr>
<th>Course Name :</th>
<td><?= $getcourses2->title; ?></td>
</tr>
<tr>
<th>Duration :</th>
<td><?= $getcourses2->duration/12; ?> Years</td>
</tr>
<tr>
<th>Subjects :</th>
<td class="center">
<?php $getsubjects= find_all("select * from subjects where courseid='$getcourses->id'");
while(#$getsubs = fetch_array($getsubjects)){
?>
<?= $getsubs->name; ?><br>
<?php } ?>
</td>
</tr>
<tr>
<th>Monthly Fee :</th>
<td><?= $getcourses2->monthlyfee ; ?></td>
</tr>
<tr>
<th>Examination Fee :</th>
<td><?= $getcourses2->examinationfee; ?></td>
</tr>
<tr>
<th>Addmission Fee :</th>
<td><?= $getcourses2->addmissionfee; ?></td>
</tr>
<tr>
<th>Status :</th>
<td class="center">
<?php if($getcourses2->status == 1){ ?>
<span class="label label-success">Active</span>
<?php }
else{
?>
<span class="label label-important">Blocked</span>
<?php } ?>
</td>
</tr>
<tr>
<th>Actions :</th>
<td class="center">
<a class="btn btn-success" href="editcourse.php?course=<?= $getcourses->id; ?>">
<i class="halflings-icon white edit"></i>
</a>
<?php if($getcourses2->status == 1){ ?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=block&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php }
else{
?>
<a class="btn btn-danger" href="disable.php?course=<?= $getcourses->id; ?>&&action=unblock&&page=courses">
<i class="halflings-icon white trash"></i>
</a>
<?php } ?>
</td>
</tr>
<?php } ?>
</thead>
<tbody>
</table>
enter code here
change the table titles contents to anchor tags
for example as
ID
and then in server side , process the query as
$sort = 'id';
if(isset($_REQUEST['sortby'])&&str_replace(' ','',$_REQUEST['sortby'])!="") $sort = $_REQUEST['sortby'];
$queryText= "select * from table_name where order by ".$sort;
make sure that the value passed by the href is the attribute name in your sql table
this code makes the query to work as sorted default by id.. if a user uses another title, it will switch as needed.
hopes this works..
NOTE: people interested in down voting, please specify the reason