Expanding Rows for Unique Checkboxes
        Posted  
        
            by 
                Marc Morgan
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Marc Morgan
        
        
        
        Published on 2012-11-07T16:58:58Z
        Indexed on 
            2012/11/07
            16:59 UTC
        
        
        Read the original article
        Hit count: 324
        
I was just recently given a project for my job to write a script that compares two mysql databases and print out information into an html table. Currently, I am trying to insert a checkbox by each individual's name and when selected, rows pertaining to that individual will expand underneath the person's name. I am combining javascript into my script to do this, although I really have no experience is it. The problem I am having is that when any checkbox is selected, all the rows for each individual is expanding instead of the rows pertaining only to the one individual selected.
Here is the coding so far:
<?php
$link = mysql_connect ($server = "harris.lib.fit.edu", $username = "", $password =     "") or die(mysql_error());
$db = mysql_select_db ("library-test") or die(mysql_error());
$ids = mysql_query("SELECT * FROM `ifc_studylog`") or die(mysql_error()); //not single quotes (tilda apostrophy)
    $x=0;
    $n=0;
    while($row = mysql_fetch_array( $ids ))
    {           
        $tracksid1[$x] = $row['fitID'];
        $checkin[$x] = $row['checkin'];
        $checkout[$x] = $row['checkout'];
        $n++;
        $x++;
    }
$names = mysql_query("SELECT * FROM `ifc_users`") or die(mysql_error()); //not single quotes (tilda apostrophy)
    $x=0;
    while($row = mysql_fetch_array( $names ))
    {           
        $tracksnamefirst[$x] = $row['firstName'];
        $tracksnamesecond[$x] = $row['lastname'];
        $tracksid2[$x] = $row['fitID'];
        $tracksuser[$x] = $row['tracks'];
        $x++;           
    }
$x=0;   
foreach($tracksid2 as $comparename)
{   
    $chk = strval($x);
?>      
                <script type='text/javascript' src='http://code.jquery.com/jquery-1.4.2.js'></script>
                <script type='text/javascript'>     
                    $(window).load(function () {
                        $('.varx').click(function () {
                            $('.text').toggle(this.checked);
                    });});
                </script>
<?php       
    echo '<td><input id = "<?=$chk?>" type="checkbox" class="varx" /></td>';
    echo '<td align="center">'.$comparename.'</td>';
    echo'<td align="center">'.$tracksnamefirst[$x].'</td>';
    echo'<td align="center">'.$tracksnamesecond[$x].'</td>'; 
    $z=0;
    foreach($tracksid1 as $compareid)
    {
        $HH=0;
        $MM =0;
        $SS =0;
        if($compareid == $comparename)// && $tracks==$tracksuser[$x])
        {
            $SS = sprintf("%02s",(($checkout[$z]-$checkin[$z])%60));
            $MM = sprintf("%02s",(($checkout[$z]-$checkin[$z])/60 %60));
            $HH = sprintf("%02s",(($checkout[$z]-$checkin[$z])/3600 %24));
             //  echo'<td align="center">'.$HH.':'.$MM.':'.$SS.'</td>';
                    echo '</tr>';
             echo '<tr>';
               echo "<td id='txt' class='text' align='center' colspan='2' style='display:none'></td>";
               echo "<td id='txt' class='text' align='center' style='display:none'>".$checkin[$z]."</td>";
               echo  '</tr>';
        }
        echo '<tr>';
        $z++;
        echo  '</tr>';
    }
$x++;
}   
}
?>
Any Help is appreciated and sorry if I am too vague on the subject. The username and password is left off for security purposes.
© Stack Overflow or respective owner