Question

Hi I am totally stuck on this one. I am using tablesorter on data pulled from a mysql database. The problem is, based on criteria, I can have multiple tables pulled and displayed.

My problem is that tablesorter will only sort the first table instance.

This is the code I am using for the tablesorter. Basic use of it.

<script type="text/javascript" >
$(document).ready(function()
{
$("#table-2").tablesorter();
}

And this is how I pull the data and use it with tablesorter. It is the Branchname that can change. If a user is assigned more than one branch they get multiple tables. This is where I'm stuck on implementing tablesorter on any table past the first instance.

$result=mysql_query("SELECT id FROM users WHERE username='$username'");
$idary=mysql_fetch_assoc($result);
$id=$idary['id'];
$result0=mysql_query("SELECT branch_id FROM access WHERE userid='$id'");
while ($row1=mysql_fetch_assoc($result0))
{
$branch_id=$row1['branch_id'];
$result=mysql_query("select distinct(name) from location where id='$branch_id'");
$nameary=mysql_fetch_assoc($result);
$branchname=$nameary['name'];
?>
<table>
        <thead>
            <b><br><?echo $branchname; ?></b>
        </thead>
</table>
<div>
    <table id='table-2' class='tablesorter'>
        <thead>
            <tr>
                <thCreator</th>
                <th><center>TeamName</th>
                <th><center>Tech Tot</th>
                <th><center>Tot W/O</th>
                <th><center>Tot S/C</th>
            </tr>
        </thead>
    // get team creators from province
$result1=mysql_query("select distinct(teamcreator) from techteams where....

I'm thinking I would need to use some form of incrementing tablename to match the number of tables pulled but I'm stuck on how to do this. I could be wrong on that assumption and there might be a much easier way of doing this.

If anyone has any pointers in the right direction I'd love some tips.

Cheers, -Colin.

Was it helpful?

Solution

you could try to give your tables an own class instead of an id.

<table class='mytables'>

<script type="text/javascript" >
$(document).ready(function()
{
  $(".mytables").tablesorter();
}
</script>

or maybe only give them the table-sorter class and in your script you try something like this:

$("table").tablesorter();

OTHER TIPS

Try it:

$(".tablesorter").tablesorter();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top