I have a PHP file that displays a grid table. I need to fix the headers, but still be able to scroll horizontally. I would like to do this with straight CSS and no Javascript.
I have searched all over Google and SO. Here are a couple of pages closest to what I would like to emulate, but they use Javascript:
http://handsontable.com/demo/fixed.html
Take a look at my code. Perhaps my code could be changed or something:
<?php
$select = "SELECT * FROM `dispatch`";
$query = @mysql_query($select) or die ();
$resnum = mysql_num_rows($query);
if($resnum == 0){
echo "<div>Your search returned no results</div>";
}
else{
echo "<table>\n";
echo "<thead><tr>" .
echo "<th>Update</th>" .
echo "<th>BOL</th>" .
echo "<td>Container</th>" .
echo "<td>Status</th>" .
*** there are like 15 more <th> headers ***
echo "</tr></thead>\n";
The code directly above are the headers that I need to remain fixed, but they need to also scroll horizontally.
Here is the rest of the code for the actual data that is displayed in TD tags:
while(($Row = mysql_fetch_assoc($query)) !== FALSE){
echo "<tbody><tr>";
echo "<td>{$Row[UPDATE]}</td>";
echo "<td>{$Row[BOL]}</td>";
echo "<td>{$Row[CONTAINER]}</td>";
echo "<td>{$Row[STATUS]}</td>";
*** again, there are like 15 more TD tags that showdata retrieved from query ***
echo "</tr></tbody>\n";
};
echo "</table>\n";
}
?>
If I forgot to close a tag or add a semi-colon, please let it slide. Just know that this code works.
I just need to figure out how to fix the HEADERS and still be able to scroll them horizontally.
I know this can be done without javascript. I've tried several different CSS methods to make this work. I can get the header to stick, but it won't scroll horizontally.
I'm not really sure how to label the CSS so that it will display correctly. I've tried DISPLAY: BLOCK; TABLE-COLLAPSE: COLLAPSE; OVERFLOW: SCROLL;
and many other methods.
I just can't get the header to stick.
Any help would be appreciated. Do I need to utilize DIVs within the table? I've seen and tried that as well. Perhaps the while loop in the middle of the table is throwing everything off.