kevinritt Posted February 15, 2009 Share Posted February 15, 2009 I am trying to get data to display on a webpage. I have everything working but I cannot get the table cells to stay a consistent width. I've tried setting each cell to a specififc width - didn't work. I tried wrapping the text - didn't work. I've been at it for hous - pleeeeaaaassssseeee help. Here's my CSS code: <style type="text/css"> <!-- .display { font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #242424; background-color: #FFFFFF; text-align: left; vertical-align: top; padding: 4px; } .mainTable { background-color: #BEBEBE; padding: 3px; } --> </style> ... and here's the PHP: <table cellspacing="1" class="mainTable"> <tr> <td width="50px" class="display">ID</td> <td width="150px" class="display">Name</td> <td width="150px" class="display">Name (2)</td> <td width="450px" class="display">Address</td> <td width="70px" class="display">Phone</td> <td width="200px" class="display">Email</td> <td width="80px" class="display">Exp Date</td> <td width="80px" class="display">Membership Type</td> <td width="120px" class="display">Child(ren)'s Name(s)</td> <td width="300px" class="display">Interests</td> <td width="80px" class="display">Date added</td> <td width="80px" class="display">added</td> <td width="150px" class="display">Additional</td> </tr></table> <?php $sql = mysql_query( "SELECT * FROM memberships" ) or die("SELECT Error: ".mysql_error()); // start the while statement to get results from database while ($row = mysql_fetch_array($sql)) { // foreach row in the while loop.. foreach($row as $key=>$value){ // convert the long winded $row[''] to simple variable // also cleaning the data of slashes for security ValidateOutput() (look at clean.php) $$key = ValidateOutput($value); } // display data in an HTML table for viewing echo '<table cellspacing="1" class="mainTable"> <tr> <td class="display">'.$memberID.'</td> <td class="display">'.$firstName.' '.' '.$lastName.'</td> <td class="display">'.$firstName2.' '.' '.$lastName2.'</td> <td class="display">'.$address.' '.' '.$city.' '.' '.$state.' '.' '.$zip.'</td> <td class="display">'.$telephone.'</td> <td class="display">'.$email.'</td> <td class="display">'.$expiration.'</td> <td class="display">'.$type.'</td> <td class="display">'.$childName.'</td> <td class="display">'.$interests.'</td> <td class="display">'.$dateAdded.'</td> <td class="display">'.$added.'</td> <td class="display">'.$additionalNotes.'</td> </tr> </table>'; } ?> Here's the results: http://flw.org/memberships/admin/index.php I want all the cells to line up in each row Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/ Share on other sites More sharing options...
Philip Posted February 15, 2009 Share Posted February 15, 2009 <table cellspacing="1" class="mainTable"> <tr> <td width="50px" class="display">ID</td> <td width="150px" class="display">Name</td> <td width="150px" class="display">Name (2)</td> <td width="450px" class="display">Address</td> <td width="70px" class="display">Phone</td> <td width="200px" class="display">Email</td> <td width="80px" class="display">Exp Date</td> <td width="80px" class="display">Membership Type</td> <td width="120px" class="display">Child(ren)'s Name(s)</td> <td width="300px" class="display">Interests</td> <td width="80px" class="display">Date added</td> <td width="80px" class="display">added</td> <td width="150px" class="display">Additional</td> </tr> <?php $sql = mysql_query( "SELECT * FROM memberships" ) or die("SELECT Error: ".mysql_error()); // start the while statement to get results from database while ($row = mysql_fetch_array($sql)) { // foreach row in the while loop.. foreach($row as $key=>$value){ // convert the long winded $row[''] to simple variable // also cleaning the data of slashes for security ValidateOutput() (look at clean.php) $$key = ValidateOutput($value); } // display data in an HTML table for viewing echo ' <tr> <td class="display">'.$memberID.'</td> <td class="display">'.$firstName.' '.' '.$lastName.'</td> <td class="display">'.$firstName2.' '.' '.$lastName2.'</td> <td class="display">'.$address.' '.' '.$city.' '.' '.$state.' '.' '.$zip.'</td> <td class="display">'.$telephone.'</td> <td class="display">'.$email.'</td> <td class="display">'.$expiration.'</td> <td class="display">'.$type.'</td> <td class="display">'.$childName.'</td> <td class="display">'.$interests.'</td> <td class="display">'.$dateAdded.'</td> <td class="display">'.$added.'</td> <td class="display">'.$additionalNotes.'</td> </tr> '; } ?> </table> Use rows (<tr>) instead of new tables for each mysql row Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762520 Share on other sites More sharing options...
allworknoplay Posted February 15, 2009 Share Posted February 15, 2009 KingPhilip is right. what you were doing is that each row was basically it's own table. make the main table in charge of the column widths and the rest of the TR's will just follow.... Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762522 Share on other sites More sharing options...
kevinritt Posted February 15, 2009 Author Share Posted February 15, 2009 I'm not sure how to write that - can you give an example? Each variable is in its own <td> Where would I edit this code: echo ' <tr> <td class="display">'.$memberID.'</td> <td class="display">'.$firstName.' '.' '.$lastName.'</td> <td class="display">'.$firstName2.' '.' '.$lastName2.'</td> <td class="display">'.$address.' '.' '.$city.' '.' '.$state.' '.' '.$zip.'</td> <td class="display">'.$telephone.'</td> <td class="display">'.$email.'</td> <td class="display">'.$expiration.'</td> <td class="display">'.$type.'</td> <td class="display">'.$childName.'</td> <td class="display">'.$interests.'</td> <td class="display">'.$dateAdded.'</td> <td class="display">'.$added.'</td> <td class="display">'.$additionalNotes.'</td> </tr> '; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762524 Share on other sites More sharing options...
Philip Posted February 15, 2009 Share Posted February 15, 2009 <table cellspacing="1" class="mainTable"> <tr> <td width="50px" class="display">ID</td> <td width="150px" class="display">Name</td> <td width="150px" class="display">Name (2)</td> <td width="450px" class="display">Address</td> <td width="70px" class="display">Phone</td> <td width="200px" class="display">Email</td> <td width="80px" class="display">Exp Date</td> <td width="80px" class="display">Membership Type</td> <td width="120px" class="display">Child(ren)'s Name(s)</td> <td width="300px" class="display">Interests</td> <td width="80px" class="display">Date added</td> <td width="80px" class="display">added</td> <td width="150px" class="display">Additional</td> </tr> <?php $sql = mysql_query( "SELECT * FROM memberships" ) or die("SELECT Error: ".mysql_error()); // start the while statement to get results from database while ($row = mysql_fetch_array($sql)) { // foreach row in the while loop.. foreach($row as $key=>$value){ // convert the long winded $row[''] to simple variable // also cleaning the data of slashes for security ValidateOutput() (look at clean.php) $$key = ValidateOutput($value); } // display data in an HTML table for viewing echo ' <tr> <td class="display">'.$memberID.'</td> <td class="display">'.$firstName.' '.' '.$lastName.'</td> <td class="display">'.$firstName2.' '.' '.$lastName2.'</td> <td class="display">'.$address.' '.' '.$city.' '.' '.$state.' '.' '.$zip.'</td> <td class="display">'.$telephone.'</td> <td class="display">'.$email.'</td> <td class="display">'.$expiration.'</td> <td class="display">'.$type.'</td> <td class="display">'.$childName.'</td> <td class="display">'.$interests.'</td> <td class="display">'.$dateAdded.'</td> <td class="display">'.$added.'</td> <td class="display">'.$additionalNotes.'</td> </tr> '; } ?> </table> Use rows (<tr>) instead of new tables for each mysql row See above - I already changed it for you Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762525 Share on other sites More sharing options...
kevinritt Posted February 15, 2009 Author Share Posted February 15, 2009 Sorry guys I started to respond before the new posts came back Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762526 Share on other sites More sharing options...
kevinritt Posted February 15, 2009 Author Share Posted February 15, 2009 worked like a charm Quote Link to comment https://forums.phpfreaks.com/topic/145256-cant-get-table-cells-consistent-in-mysql-data-display/#findComment-762530 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.