How to make paginated table? - php

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>

Related

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>

MPDF Checkbox not showing in PDF only dot

Im using MPDF to output my html form into a PDF. But my problem is, when it converts to PDF the box shape of checkbox is gone, below is the sample how i coded the checkbox
<input type='checkbox' name='opening' value='referal' checked="checked"> Check 1
<input type='checkbox' name='opening' value='referal2' checked="checked"> Check 2
Here's the html output before converting:
Here's the html output before converting:
Here's the mpdf OUTPUT:
Here's the mpdf output:
As you can see, the check '✓' became dot '.' and the box shape is gone.
Is there something wrong with my code? Or It is just not possible with MPDF?
But let me add, if I'm using radio button, all is fine. But what I need is checkbox not radio button.
Radio Button OUTPUT:Radio Button
Heres my full code GeneratePDF.php
<?php
include('mpdf60/mpdf.php');
$html .=
"
<!DOCTYPE html>
<html>
<head>
<title>Applicant Information Sheet</title>
<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css'>
<link rel='stylesheet' type='text/css' href='style.css'>
</head>
<body>
<div class=' header-logos text-center'>
<img src='headerimage/logo1.png' width='270' height='90' class=''>
<img src='headerimage/logo2.png' width='170' height='130' class='' >
<img src='headerimage/logo3.png' width='180' height='90' class=''>
</div>
<div class='container top-head'>
<p class='form-hrm'>FORM-HRM-R-003</p>
<hr>
<div class='col-lg-12 col-md-12 col-sm-12 col-xs-12'>
<div class='profile-pic'></div>
<p class='blackened-head'>APPLICANTS INFORMATION SHEET</p>
<form class='head-form'>
<span class='detail1'>Date</span><span class='user-texts'>:</span><span class='user-texts bold'> Nicky Jacobo</span><br>
<span class='detail2'>Position</span><span class='user-texts'>:</span> <span class='choice1 '>1st choice</span><span class='user-texts'>:</span> <span class='user-texts bold'>Information Technology</span><span class='choice2'> 2nd choice</span><span class='user-texts'>: </span><span class='user-texts bold'>Hotel Management</span><br>
<span class='detail3'>Salary Expectation</span><span class='user-texts'>:</span><span class='user-texts bold'>100,000</span><br>
<span class='detail4'>Availability to Start</span><span class='user-texts'>: </span><span class='user-texts bold'>Anytime</span><br>
</form>
<p class='blackened peros'>PERSONAL INFORMATION</p>
</div>
</div><!-- End of top-head -->
<!--==========================================
PERSONAL INFORMATION
============================================= -->
<div class='container personal-information'>
<table>
<tr class='zero-row'>
<th colspan='6' >NAME: <span class='outs'>
<span class='lastname ' style='font-weight: 900;'>JACOBO</span>
<span class='firstname' style='font-weight: 900;'>NICKY</span>
<span class='midname' style='font-weight: 800;'>CABALU</span>
</span><br>
<span class='lastnamedet'>(last name)</span>
<span class='firstnamedet'>(first name)</span>
<span class='midnamedet'>(middle name)</span>
</th>
</tr>
<tr class='first-row'>
<td>NICKNAME<br><span class='user-texts bold'>Nicks</span></td>
<td>BIRTHDATE (mm/dd/yyyy)<br><span class='user-texts bold'>10/25/1994</span></td>
<td>BIRTHPLACE<br><span class='user-texts bold'>Tokyo Japan</span></td>
<td>AGE<br><span class='user-texts bold'>18</span></td>
<td>HEIGHT<br><span class='user-texts bold'>5'7'</span></td>
<td>WEIGHT<br><span class='user-texts bold'>60kg</span></td>
</tr>
<tr class='second-row'>
<td colspan='6'>CITY ADDRESS: <span class='bold'>Plaridel Bulacan</span> </td>
</tr>
<tr class='third-row'>
<td colspan='6'>PROVINCIAL ADDRESS: <span class='bold'>Plaridel Bulacan</span> </td>
</tr>
<tr class='fourth-row'>
<td rowspan='2' ><span class='residentstatus'>RESIDENTIAL STATUS:</span>
<form>
<input type='checkbox' name='gender' value='own' checked='checked'> Own House<br>
<input type='checkbox' name='gender' value='rent'> Rent<br>
<input type='checkbox' name='gender' value='other' > Others (specify): <span class='bold'>Own Mansion</span>
</form>
</td>
<td rowspan='2'><span class='gender'>GENDER:</span>
<form>
<input type='checkbox' name='gender' value='male' checked='checked'> Male<br>
<input type='checkbox' name='gender' value='female' > Female<br>
</form>
</td>
<td colspan='2'>
MOBILE TEL. #: <span class='bold outs'>0926-107-4423</span><br><br>
RESIDENCE TEL. #: <span class='bold outs'>02-25429</span>
</td>
<td colspan='2' >EMAIL ADDRESS:<br><span class='bold outs'>yinkciworks#gmail.com</span></td>
</tr>
<tr class='fifth-row'>
<td colspan='4'>CIVIL STATUS:<br>
<input type='checkbox' name='civil-stat' value='single' checked='checked'> Single
<input type='checkbox' name='civil-stat' value='married' > Married
<input type='checkbox' name='civil-stat' value='single-parent' > Single Parent
<input type='checkbox' name='civil-stat' value='widow' > Widow
<input type='checkbox' name='civil-stat' value='other-status'> Others:
<span class='bold'>Complicated</span>
</td>
</tr>
<tr class='sixth-row'>
<td colspan='2' rowspan='2'>Nationality<br><br>
<input type='checkbox' name='filipino' value='filipino' checked='checked'> Filipino<br>
<input type='checkbox' name='othersnationalit' value='female' > Others (specify):
<span class='bold outs'>Alien Gender</span>
</td>
<td colspan='4'>SSS:
<span class='bold'>29-7098-7685-456</span>
       
TIN:
<span class='bold'>29-7098-7685-456</span>
</td>
</tr>
<tr class='seventh-row'>
<td colspan='4'>CURRENT ACTIVITIES:
<span class='bold'>Nandemonai</span>
</td>
</tr>
</table>
<!--==========================================
EMPLOYMENT HISTORY
============================================= -->
<p class='blackened'>EMPLOYMENT HISTORY</p>
<table class='table-two'>
<tr>
<th>COMPANY NAME</th>
<th>LAST POSITION</th>
<th>IMMEDIATE SUPERIOR</th>
<th>CONTACT NUMBER</th>
<th>INCLUSIVE DATES</th>
<th>REASON FOR LEAVING</th>
<th>SALARY</th>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
<tr class='table2-first-row'>
<td><span class='bold'>iConcept Global</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Supervisor</span></td>
<td><span class='bold'>0926-107-4423</span></td>
<td><span class='bold'>Oct 25 1994</span></td>
<td><span class='bold'>Mayaman na</span></td>
<td><span class='bold'>100,000</span></td>
</tr>
</table>
<!--==========================================
FAMILY BACKGROUND
============================================= -->
<p class='blackened'>FAMILY BACKGROUND</p>
<table class='table-three'>
<tr>
<th></th>
<th>NAME</th>
<th>AGE</th>
<th>OCCUPATION</th>
<th>COMPANY/SCHOOL</th>
</tr>
<tr>
<td>Father</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Mother</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td rowspan='4'>Brothers & Siters</td>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td><span class='bold'>Nicky Jacobo</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Spouse</td>
<td><span class='bold'>Not available</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
<tr>
<td>Children</td>
<td><span class='bold'>Not available</span></td>
<td><span class='bold'>18</span></td>
<td><span class='bold'>Web Developer</span></td>
<td><span class='bold'>Secret</span></td>
</tr>
</table>
<!--==========================================
REFERENCES
============================================= -->
<p class='blackened'>REFERENCES</p>
<table class='table-four'>
<tr>
<th>NAME</th>
<th>POSITION</th>
<th>COMPANY</th>
<th>ADDRESS</th>
<th>CONTACT NO.</th>
</tr>
<tr>
<td><span class='bold centerme'>Shana Hirai</span></td>
<td><span class='bold centerme'>Flame Haze</span></td>
<td><span class='bold centerme'>Shakugan no Shana</span></td>
<td><span class='bold centerme'>Anime</span></td>
<td><span class='bold centerme'>0926-107-4423</span></td>
</tr>
<tr>
<td rowspan='9' colspan='3' class='etu'>How did you know of the opening?<br>
<input type='checkbox' name='opening' value='news' checked> Newspaper Ad <br>
<input type='checkbox' name='opening' value='school'> School Placement <br>
<input type='checkbox' name='opening' value='walkin'> Walk-in<br>
<input type='checkbox' name='opening' value='referal' checked> Referral of: <span class='bold outs'>Friend</span> <br>
<input type='checkbox' name='opening' value='other-ads' checked> Others (specify): <span class='bold outs'>Facebook Ads</span><br><br>
</td>
<td rowspan='9' colspan='2'>
<span class='emergency italic'>In case of emergency please contact:</span><br>
Name: <span class='bold'> Sakai Yuji</span><br>
Contact No.: <span class='bold'>0926-107-4423</span><br>
Relation to you: <span class='bold'>Tomodachi</span><br><br>
</td>
</tr>
</table>
<p class='ihereby'>I hereby certify that the above information is true and correct and I hereby authorize Cabalen to verify the said information.</p>
<table class='last-part'>
<tr>
<th><span class=''>   signed already</span><br><br>
<span class='sign-details'> Applicant's Signature</span></th>
<th><span class=''>                          Oct 23 2017</span><br><br>
<span class='date-details'>                          Date</span></th>
</tr>
</table>
</div>
</body>
</html>
";
$mpdf=new mPDF('utf-8', 'Letter', 0, '', 2, 2, 12, 2, 2, 2);
$mpdf->WriteHTML($html);
$mpdf->SetDisplayMode('fullpage');
$mpdf->shrink_tables_to_fit = 1;
$mpdf->Output();
?>
The mPDF docs state that the first argument of Output() is the file path, second is the saving mode - you need to set it to 'F'.
$mpdf->Output('filename.pdf','F'); //Only save to File
Updated: You may need this too:
$mpdf->Output('filename.pdf','D');
I already found the cause, its the maxcdn bootstrap link, I only removed the link then everything went fine.

How to pass the php parameter in jquery

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>

Expand immidiate next even rows onclicking odd rows using jquery

I want to create table like in this site:
https://www.avast.com/en-in/exploit-protection.php
I tried with below code but something is happening wrong , I am beginner of jquery.Reading data from mysql php to show.
HTML:
$(document).ready(function(){
$("#myTable tr:odd").addClass("odd");
$("#myTable tr:not(.odd)").hide();
$("#myTable tr:first-child").show();
});
$(document).ready(function(){
$("#myTable tr").click(function(){
$(this).next("tr").toggle();
$(this).find(".arrow").toggleClass("up");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table id ='myTable' class='tablesorter' style='table-layout:fixed;'>
<thead>
<tr>
<th class='header' width='4%'>Wild</th>
<th class='header ' width='12%'>Release Date</th>
<th class='header' width='12%'>Exploit Name1</th>
<th data-sorter='false' width='18%'>Name2</th>
<th data-sorter='false' width='53%'>Comments</th>
<th data-sorter='false' width='1%'></th>
</tr>
</thead>
<tbody>
<tr>
<td> <i hidden>1</i><img src='ex.png' alt='' border=3 height=25 width=25></img>
</td>
<td>03/11/2015</td>
<td><b> CVE-2015-1623</b></td>
<td style='word-wrap:break-word;'>
<ul>
<li>ABC</li>
<li>XYZ</li>
<li>PQR</li>
</ul>
</td>
<td style='word-wrap:break-word;'>
Microsoft Internet Explorer 11 allows remote attackers to execute arbitrary code or cause ...
</td>
<td>
<div class='arrow'></div>
</td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td>
<b>Link: </b>
<ul>
<li><a href =http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1623 target ='_blank'>http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2015-1623<br></a></li>
</ul>
</td>
<td></td>
</tr>
<tr>
Please let me know what is wrong in jquery.

how to use sql query result in html table

I am trying to create a html table showing results from php sql query. it is a result page of students php code is as under
$r1=$_GET["r"];
$con=mysqli_connect(localhost,chumspai_tlss,Tls121,chumspai_tlsResult);
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM nursery_blue_ WHERE sr_='$r1'");
while($row = mysqli_fetch_array($result))
{
html code is
<pre>
<form name="frmResult" id="frmResult" action="" method="post" onsubmit="return checkEmpty();">
<table width="80%" cellpadding="5" cellspacing="5" border="0">
<tr>
<td class="heading noborder">Enter Your Roll Number:</td>
<td class="noborder"><input type="text" id="r" name="r" value="" /></td>
</tr>
<tr>
<!--
<td class="heading noborder">Enter Your Name:</td>
<td class="noborder"><input type="text" id="name" name="name" value="" /></td>
</tr>
<tr>
<td class="heading noborder">Search by</td>
<td class="noborder"><input type="radio" id="option" name="option" value="rno" checked="checked" />
Roll No
<input type="radio" id="option" name="option" value="name" />
Name </td>
</tr>
-->
<tr>
<td class="noborder"> </td>
<td class="noborder"><input type="submit" name="submit" value="Search" />
<input type="reset" name="reset" value="Clear" />
</td>
</tr>
<!--<tr>
<td colspan="2"> <embed src="images/wait.swf"></embed></td>
</tr> -->
</table>
</form>
<div style="border:1px solid #000000;">
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr>
<td class="heading grey" width="30%">RNO</td>
<td><?php
Print $row['sr_'];
?>
</td>
</tr>
<tr>
<td class="heading grey">NAME</td>
<td class="shade"></td>
</tr>
<tr>
<td class="heading grey">FATHER</td>
<td></td>
</tr>
<tr>
<td class="heading grey">regno</td>
<td></td>
</tr>
</table>
<table width="100%" cellpadding="10" cellspacing="0" border="0">
<tr class="grey">
<td rowspan="2" class="heading">Sr.no </td>
<td rowspan="2" class="heading">Name of subject </td>
<td rowspan="2" class="heading">Maximum Marks</td>
<td colspan="7" class="heading">detail of marks Obtained</td>
<tr class="grey">
<td class="heading">PART ONE</td>
<td class="heading">Total</td>
</tr>
<tr>
<td>1</td>
<td>Urdu</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>2</td>
<td>English</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr>
<td>3</td>
<td>Islamyat</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>4</td>
<td>pakstudies</td>
<td></td>
<td> </td>
<td></td>
</tr>
<tr class="shade">
<td>6</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr>
<td>7</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>8</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="shade">
<td>9</td>
<td></td>
<td></td>
<td></td>
<td>0</td>
</tr>
<tr class="grey">
<td colspan="2" class="heading">TOTAL</td>
<td class="heading">1100</td>
<td colspan="4" class="heading"></td>
</tr>
<tr class="grey">
<td colspan="3" class="heading">NOTIFICATION</td>
<td class="heading"></td>
<td class="heading"></td>
<td colspan="2" class="heading"></td>
</tr>
<tr>
<td colspan="7">(i) This provisional result intimation is issued as a notice only. Errors and omissions are excepted.</td>
</tr>
</table>
</pre>
please help me how to embed this php query with this html table and html form also.
you are not so far.
The variable $row is an array containing your data. Try this to see it's structure in your while call:
print_r($row);
Using this command you will see the name of each item of your array. Note it somewhere. Then you can do something like this:
...<td><?php echo $row['desired_column_name']; ?></td>...
If you receive data from your mysql query, this should do the trick.
Hope it helps,
Paul
Try This :
$result = mysql_query("select * from emp");
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td id=SrNo$cnt >".$row['eno']."</td>";
echo "<td id=ItemId$cnt >".$row['eId']."</td>";
echo "<td>". "<button name='Update' id='update' onclick='show(".$cnt.")'>UPDATE</button>"."</td>";
echo "<td>". "<button name='Report' id='show' onclick='Report(".$row['SrNo'].")'>REPORT</button>"."</td>";
echo "</tr>";
echo "<div id=show$cnt>";
echo "</div>";
$cnt++;
}

Categories