Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

problem in IE with aligning table

Question posted by: gubbachchi (Member) on May 13th, 2008 07:03 AM
Hi all,

I have a problem with css table. The code below works fine with firefox but the problem is with Internet explorer.
This code actually fetches data from mysql database and display it in the form of table for which I have used CSS. In firefox the fetched are aligned properly but in Internet explorer, the width alignment is messed up.
Here is the code I am using

main.php
Code: ( text )
  1. <html>
  2. <head>
  3. <link href="main.css" rel="stylesheet" type="text/css" />
  4. </head>
  5. <body>
  6. <?php
  7. include("Con.php");
  8.  
  9. $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
  10. $result = mysql_query($query);
  11. $num = mysql_num_rows($result);
  12.  
  13. echo ("<table class=meal-table>");
  14. echo ("<tr>");
  15. echo ("<th scope=col>"."Food Desc"."</td>");
  16. echo ("<th scope=col>"."Enter Amount"."</td>");
  17. echo ("<th scope=col>"."Msre Desc"."</td>");
  18. echo ("</tr>");
  19. echo ("</table>");
  20.  
  21. while ($values = mysql_fetch_array($result))
  22. {
  23.     echo ("<form name='addmenu' action ='' method='POST'");
  24.     echo ("<table class=meal-table>");
  25.     echo ("<tr>");
  26.     echo ("<td>".$values['DEG1']."</td>");
  27.     echo ("<td>");
  28.     echo ("<input type='textbox' size='3' name='msreval'>");
  29.     echo ("</td>");
  30.     echo ("<td>".$values['DEG2']."</td>");
  31.     echo ("<td>");
  32.     echo ("<input type='submit' value='add' name='submit' size='3'>");
  33.     echo ("</td>");
  34.     echo ("</tr>");
  35.     echo ("</table>");
  36.     echo ("</form>");   
  37. }
  38. ?>
  39. </body>
  40. </html>


main.css
Code: ( text )
  1. .meal-table
  2. {
  3.   padding: 0;
  4.   margin: 0;
  5.   border-collapse: collapse;
  6. }
  7. .meal-table th
  8. {
  9.   border: 1px solid #000;
  10.   padding: 0.5em;
  11.   text-align: left;
  12.   width:150px;
  13.   height:10px;
  14. }
  15. .meal-table td
  16. {
  17.   border: 1px solid #000;
  18.   padding: 0.5em;
  19.   text-align: left;
  20.   width:150px;
  21.   height:10px;
  22. }


Could anyone please help me to solve this problem

With regards
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
harshmaul's Avatar
harshmaul
Expert
481 Posts
May 13th, 2008
08:20 AM
#2

Re: problem in IE with aligning table
Quote:
Originally Posted by gubbachchi
Hi all,

I have a problem with css table. The code below works fine with firefox but the problem is with Internet explorer.
This code actually fetches data from mysql database and display it in the form of table for which I have used CSS. In firefox the fetched are aligned properly but in Internet explorer, the width alignment is messed up.
Here is the code I am using

main.php
Code: ( text )
  1. <html>
  2. <head>
  3. <link href="main.css" rel="stylesheet" type="text/css" />
  4. </head>
  5. <body>
  6. <?php
  7. include("Con.php");
  8.  
  9. $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
  10. $result = mysql_query($query);
  11. $num = mysql_num_rows($result);
  12.  
  13. echo ("<table class=meal-table>");
  14. echo ("<tr>");
  15. echo ("<th scope=col>"."Food Desc"."</td>");
  16. echo ("<th scope=col>"."Enter Amount"."</td>");
  17. echo ("<th scope=col>"."Msre Desc"."</td>");
  18. echo ("</tr>");
  19. echo ("</table>");
  20.  
  21. while ($values = mysql_fetch_array($result))
  22. {
  23.     echo ("<form name='addmenu' action ='' method='POST'");
  24.     echo ("<table class=meal-table>");
  25.     echo ("<tr>");
  26.     echo ("<td>".$values['DEG1']."</td>");
  27.     echo ("<td>");
  28.     echo ("<input type='textbox' size='3' name='msreval'>");
  29.     echo ("</td>");
  30.     echo ("<td>".$values['DEG2']."</td>");
  31.     echo ("<td>");
  32.     echo ("<input type='submit' value='add' name='submit' size='3'>");
  33.     echo ("</td>");
  34.     echo ("</tr>");
  35.     echo ("</table>");
  36.     echo ("</form>");   
  37. }
  38. ?>
  39. </body>
  40. </html>


main.css
Code: ( text )
  1. .meal-table
  2. {
  3.   padding: 0;
  4.   margin: 0;
  5.   border-collapse: collapse;
  6. }
  7. .meal-table th
  8. {
  9.   border: 1px solid #000;
  10.   padding: 0.5em;
  11.   text-align: left;
  12.   width:150px;
  13.   height:10px;
  14. }
  15. .meal-table td
  16. {
  17.   border: 1px solid #000;
  18.   padding: 0.5em;
  19.   text-align: left;
  20.   width:150px;
  21.   height:10px;
  22. }


Could anyone please help me to solve this problem

With regards


I think this is a problem with how you are using PHP....

u need to print the <tr> elements using the echo.... all within the same root <table> element.....

Try this....
Code: ( text )
  1. <html>
  2. <head>
  3. <link href="main.css" rel="stylesheet" type="text/css" />
  4. </head>
  5. <body>
  6. <?php
  7. include("Con.php");
  8.  
  9. $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
  10. $result = mysql_query($query);
  11. $num = mysql_num_rows($result);
  12.  
  13. echo ("<table class=meal-table>");
  14. echo ("<tr>");
  15. echo ("<th scope=col>"."Food Desc"."</th>");
  16. echo ("<th scope=col>"."Enter Amount"."</th>");
  17. echo ("<th scope=col>"."Msre Desc"."</th>");
  18. echo ("<th scope=col>"."&nbsp;"."</th>");
  19. echo ("</tr>");
  20.  
  21. while ($values = mysql_fetch_array($result))
  22. {
  23.     echo ("<form name='addmenu' action ='' method='POST'");
  24.     echo ("<tr>");
  25.     echo ("<td>".$values['DEG1']."</td>");
  26.     echo ("<td>");
  27.     echo ("<input type='textbox' size='3' name='msreval'>");
  28.     echo ("</td>");
  29.     echo ("<td>".$values['DEG2']."</td>");
  30.     echo ("<td>");
  31.     echo ("<input type='submit' value='add' name='submit' size='3'>");
  32.     echo ("</td>");
  33.     echo ("</tr>");
  34.  
  35.     echo ("</form>");   
  36. }
  37.  
  38.     echo ("</table>");
  39. ?>
  40. </body>
  41. </html>


Also your table wasn't done properly... please examine the changes i made.... and if you don't understand the need for them ask ans we'll fill in the gaps.....

Dont Forget.... this was a PHP problem... in the sense you was using it incorrectly!!!

i hope that helped

Reply
gubbachchi's Avatar
gubbachchi
Member
51 Posts
May 13th, 2008
09:18 AM
#3

Re: problem in IE with aligning table
Hi,

It helped me a lot. Thank you so much

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,098 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top HTML / CSS Forum Contributors