INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Trouble Displaying query results

Trouble Displaying query results

(OP)
How can I make the below code display with a locked header so that when the user is scrolling down the display the header of the table is still visible? I have tried displaying a table with just the header and then a scrollable table below it, but then the columns do not match up because the column widths of the scrollable table change. I'm sure this is something very simple that I'm missing.


CODE

echo '<div style= height:500px;overflow:auto>';
echo '<table>';
echo '<table border="1" width="100%"  cellpadding="10">';
echo '<thead><tr><th>' . implode('</th><th>', $rows[0]) . '</th></tr></thead>';
foreach($rows as $key=>$row):
  
		echo '<tbody>';
		echo '<tr>';
		foreach($rows[0] as $field):
			echo "<td bgcolor='white' align='center'>";
	                echo isset($row[$field]) ? $row[$field] : ' ';
			echo '</td>';
		endforeach;
		echo '</tr>';
	
endforeach;
echo '</tbody></table>';
echo'</div>'; 

RE: Trouble Displaying query results

I just realized that this jsfiddle example does not lock the column width between the table head and table body. There is another example here:
http://www.imaputz.com/cssStuff/bigFourVersion.htm...

These examples show a scrollable table within the page. If you do not want a scroll bar on a table and just want the table heading to appear regardless of the overall page scroll, you will need some javascript.

RE: Trouble Displaying query results

(OP)
Thanks for the example spamjim. I have the scroll function working great but my header row still scrolls with the rest of the table. Can you give me some insight into what I did wrong here?

CODE

echo '<div id="tableContainer" class="tableContainer">';
echo '<table border="1" width="99.9%"  cellpadding="10">';
echo '<thead class="fixedHeader"><tr><th>' . implode('</th><th>', $rows[0]) . '</th></tr></thead>';

foreach($rows as $key=>$row):
  
		echo '<tbody class="scrollContent">';
		echo '<tr>';
		foreach($rows[0] as $field):
			echo "<td bgcolor='white' align='center'>";
	                echo isset($row[$field]) ? $row[$field] : ' ';
			echo '</td>';
		endforeach;
		echo '</tr>';
	
endforeach;
echo '</tbody></table>';
echo '</div>';	
?> 

RE: Trouble Displaying query results

The magic is in the CSS, which is not displayed in your example. So we cannot troubleshoot how you have defined "fixedHeader" as a class in your CSS.

Also check your PHP output with an online HTML validator. ( http://validator.w3.org/ ) It looks like you are generating an excess of opening tbody tags.

When designing for PHP output, it is ideal to leave PHP out entirely until you have the HTML/CSS worked out on dummy/filler data. Once that is designed, insert your PHP functions. You are complicating your design process right now with the PHP. Try approaching this without PHP.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close