How to pass the php parameter in jquery - php

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>

Related

I want to hide table buttons

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>

Codeigniter load view with data after button submit

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

Disable the button in the table based on the td text

I have a table as follows:
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Address</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
foreach ($rslt as $value) {
?>
<tr>
<td><?= $value['order_id']?></td>
<td><?= $value['cust_name']?></td>
<td><?= $value['address']?></td>
<td><?= $value['st_size']?></td>
<td class="status"><?= $value['status']?></td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="<?=$value['order_id']?>">Assign</button></td>
</tr>
<?php
}
?>
</tbody>
</table>
What I am trying to do is, if the $value['status'] is "assigned" then I want to disable the button i.e next to this td. I have tried following code. But i could not disable the button.
$("#dataTable tbody").find("tr").each(function() {
var ratingTdText = $(this).find('td.status').text();
if (ratingTdText == 'assigned')
$(this).parent('tr').find(".btn-assign").prop("disabled",true);
});
Your button doesn't have the id btn-assign, it's a class. Use . instead of #.
Plus, in your case, $(this).parent('tr') won't find anything, since this is already the tr.
$('#dataTable tbody tr').each(function() {
if ($('.status', this).text() == 'assigned') {
$('.btn-assign', this).prop("disabled", true);
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Address</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td class="status">assigned</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
</tbody>
</table>
To add to what Zenoo said - there's no need to call find when you have a specific selector for status. Always strive to make the simplest form of the argument.
if ($('.status').text() == 'assigned') {
$('.btn-assign').prop("disabled", true);
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Address</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>a</td>
<td>b</td>
<td>c</td>
<td>d</td>
<td class="status">assigned</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
</tbody>
</table>
Here you got an easy way to do it with has and contains selectors:
$('tr:has(td.status:contains(assigned)) .btn-assign').prop("disabled", true);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-bordered" id="dataTable" width="100%" cellspacing="0">
<thead>
<tr>
<th>Order ID</th>
<th>Name</th>
<th>Address</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<tr>
<td>a1</td>
<td>b2</td>
<td>c3</td>
<td>d4</td>
<td class="status">assigned</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
<tr>
<td>a2</td>
<td>b2</td>
<td>c2</td>
<td>d2</td>
<td class="status">Not assign</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
<tr>
<td>a3</td>
<td>b3</td>
<td>c3</td>
<td>d3</td>
<td class="status">assigned</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
<tr>
<td>a4</td>
<td>b4</td>
<td>c4</td>
<td>d4</td>
<td class="status">Not assign</td>
<td><button class="btn btn-primary btn-sm btn-assign" type="button" data-id="d">Assign</button></td>
</tr>
</tbody>
</table>
Note this will select any td with containing word "assigned" even if there are other words.
Why use Javascript, you can fix it on the PHP end.
<td><button <?= ($value['status']=='assigned')?'disabled':''; ?> class="btn btn-primary btn-sm btn-assign" type="button" data-id="<?=$value['order_id']?>">Assign</button></td>

can't organise my data in my tableau

I'm using php and Angular JS and this is my code :
<table class="table table-bordered">
<thead>
<tr>
<th><Bold>Participation fille-société</Bold></th>
<th><Bold>Secteur d'activité</Bold></th>
<th><Bold>Date d'acquisition</Bold></th>
<th><Bold>Prix d'acquisition</Bold></th>
<th><Bold>Tri actualisé</Bold></th>
<th><Bold>Type d'operation</Bold></th>
<th><Bold>Participations meres</Bold></th>
<th><Bold>Action<Bold></th>
</tr>
</thead>
</tbody>
<tr >
<td><Bold><a href="consultationPFS.php?id_participationfilleS={{ps.id_participationfilleS}}">{{ps.nomParticipationFilleS}}</Bold></td>
<td><Bold>{{ps.secteurActivite}}</Bold></td>
<td><Bold>{{ps.date_aquisition}}</Bold></td>
<td><Bold>{{ps.Prix_acquisition}}</Bold></td>
<td><Bold>{{ps.tri_actualise}}</Bold></td>
<td><Bold>{{ps.tri_actualise}}</Bold></td>
<td ng-repeat="ac in DataPmers"><Bold>{{ac.nom_participation}} {{ac.pourcentage}}%</Bold></td>
<td><a type="submit" class="edit-row" href="UpdatePFS.php?id_participationfilleS={{ps.id_participationfilleS}}" title="Modifier" ><i class="fa fa-pencil"></i></a> | <a type="submit" class="delet-row" title="Supprimer" ng-click="supp(ps)"><i class="fa fa-trash"</i></button></a> | <a type="submit" class="edit-row" href="EtatPFS.php?id_participationfilleS={{ps.id_participationfilleS}}" title="Modifier" ><i class="fa fa-pencil"></i></a></td>
</tr>
</tbody>
</table><div class="box-footer clearfix">
And the result like in the picture below :
As u can see in Participations meres it give me only one data and other line of data in other column
How can I get all data of participation mere in the same column ?
Would this work for you - new row of the table for each DataPmers?
<table class="table table-bordered">
<thead>
<tr>
<th><Bold>Participation fille-société</Bold></th>
<th><Bold>Secteur d'activité</Bold></th>
<th><Bold>Date d'acquisition</Bold></th>
<th><Bold>Prix d'acquisition</Bold></th>
<th><Bold>Tri actualisé</Bold></th>
<th><Bold>Type d'operation</Bold></th>
<th><Bold>Participations meres</Bold></th>
<th><Bold>Action<Bold></th>
</tr>
</thead>
</tbody>
<tr ng-repeat="ac in DataPmers">
<td><Bold><a href="consultationPFS.php?id_participationfilleS={{ps.id_participationfilleS}}">{{ps.nomParticipationFilleS}}</Bold></td>
<td><Bold>{{ps.secteurActivite}}</Bold></td>
<td><Bold>{{ps.date_aquisition}}</Bold></td>
<td><Bold>{{ps.Prix_acquisition}}</Bold></td>
<td><Bold>{{ps.tri_actualise}}</Bold></td>
<td><Bold>{{ps.tri_actualise}}</Bold></td>
<td><Bold>{{ac.nom_participation}} {{ac.pourcentage}}%</Bold></td>
<td><a type="submit" class="edit-row" href="UpdatePFS.php?id_participationfilleS={{ps.id_participationfilleS}}" title="Modifier" ><i class="fa fa-pencil"></i></a> | <a type="submit" class="delet-row" title="Supprimer" ng-click="supp(ps)"><i class="fa fa-trash"</i></button></a> | <a type="submit" class="edit-row" href="EtatPFS.php?id_participationfilleS={{ps.id_participationfilleS}}" title="Modifier" ><i class="fa fa-pencil"></i></a></td>
</tr>
</tbody>
</table>

How to make paginated table?

I'm using bootstrap and I have used a table to echo users data by using PHP, the problem is that there's a lot of results, so I want to show pagination below that table, and I want to do this with jQuery if possible? If not I guess I will go for PHP.
How could I do it?
I have tried several plugins and different methods, but actually I'm a beginner and it didn't work smoothly for me.
One of the jQuery plugins I tried is simplePagination.js but nothing is working.
My code:
<table class="table table-striped">
<thead>
<tr>
<th width="30%">User Name</th>
<th width="35%">Email</th>
<th width="30%">Phone</th>
<th width="5%">Option</th>
</tr>
</thead>
<tbody>
<tr id="users">
<th><?php echo $row['mem_uname']; ?></th>
<td><?php echo $row['mem_email']; ?></td>
<td><?php echo $row['mem_phone']; ?></td>
<td>
<a class="btn btn-danger option"
href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
</tbody>
</table>
You could use dataTables jQuery plugin which:
Is bootstrap friendly
Includes pagination, you would only need to tweak it's length via jQuery.
See snippet below:
$('#myTable').dataTable({
"pageLength": 4
});
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css" rel="stylesheet" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js"></script>
<table id="myTable" class="table table-striped">
<thead>
<tr>
<th width="30%">User Name</th>
<th width="35%">Email</th>
<th width="30%">Phone</th>
<th width="5%">Option</th>
</tr>
</thead>
<tbody>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
<tr id="users">
<th>TEST</th>
<td>TEST</td>
<td>TEST</td>
<td>
<a class="btn btn-danger option" href="home?p=Users&delete=<?php echo $row['mem_id'];?>">Delete</a>
</td>
</tr>
</tbody>
</table>

Categories