problem in IE with aligning table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gubbachchi
    New Member
    • Jan 2008
    • 59

    problem in IE with aligning table

    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:
    <html>
    <head>
    <link href="main.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
    include("Con.php");
    
    $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    
    echo ("<table class=meal-table>");
    echo ("<tr>");
    echo ("<th scope=col>"."Food Desc"."</td>");
    echo ("<th scope=col>"."Enter Amount"."</td>");
    echo ("<th scope=col>"."Msre Desc"."</td>");
    echo ("</tr>");
    echo ("</table>");
    
    while ($values = mysql_fetch_array($result))
    {
    	echo ("<form name='addmenu' action ='' method='POST'");
    	echo ("<table class=meal-table>");
    	echo ("<tr>");
    	echo ("<td>".$values['DEG1']."</td>");
        echo ("<td>");
       	echo ("<input type='textbox' size='3' name='msreval'>");
        echo ("</td>");
        echo ("<td>".$values['DEG2']."</td>");
        echo ("<td>");
        echo ("<input type='submit' value='add' name='submit' size='3'>");
        echo ("</td>");
        echo ("</tr>");
    	echo ("</table>");
    	echo ("</form>");	
    }
    ?>
    </body>
    </html>
    main.css
    Code:
    .meal-table
    {
      padding: 0;
      margin: 0;
      border-collapse: collapse;
    }
    .meal-table th
    {
      border: 1px solid #000;
      padding: 0.5em;
      text-align: left;
      width:150px;
      height:10px;
    }
    .meal-table td
    {
      border: 1px solid #000;
      padding: 0.5em;
      text-align: left;
      width:150px;
      height:10px;
    }
    Could anyone please help me to solve this problem

    With regards
  • harshmaul
    Recognized Expert Contributor
    • Jul 2007
    • 490

    #2
    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:
    <html>
    <head>
    <link href="main.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
    include("Con.php");
    
    $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    
    echo ("<table class=meal-table>");
    echo ("<tr>");
    echo ("<th scope=col>"."Food Desc"."</td>");
    echo ("<th scope=col>"."Enter Amount"."</td>");
    echo ("<th scope=col>"."Msre Desc"."</td>");
    echo ("</tr>");
    echo ("</table>");
    
    while ($values = mysql_fetch_array($result))
    {
    	echo ("<form name='addmenu' action ='' method='POST'");
    	echo ("<table class=meal-table>");
    	echo ("<tr>");
    	echo ("<td>".$values['DEG1']."</td>");
        echo ("<td>");
       	echo ("<input type='textbox' size='3' name='msreval'>");
        echo ("</td>");
        echo ("<td>".$values['DEG2']."</td>");
        echo ("<td>");
        echo ("<input type='submit' value='add' name='submit' size='3'>");
        echo ("</td>");
        echo ("</tr>");
    	echo ("</table>");
    	echo ("</form>");	
    }
    ?>
    </body>
    </html>
    main.css
    Code:
    .meal-table
    {
      padding: 0;
      margin: 0;
      border-collapse: collapse;
    }
    .meal-table th
    {
      border: 1px solid #000;
      padding: 0.5em;
      text-align: left;
      width:150px;
      height:10px;
    }
    .meal-table td
    {
      border: 1px solid #000;
      padding: 0.5em;
      text-align: left;
      width:150px;
      height:10px;
    }
    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:
    <html>
    <head>
    <link href="main.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <?php
    include("Con.php");
    
    $query = "SELECT DEG1,DEG2 FROM lists WHERE Grp='$grp'";
    $result = mysql_query($query);
    $num = mysql_num_rows($result);
    
    echo ("<table class=meal-table>");
    echo ("<tr>");
    echo ("<th scope=col>"."Food Desc"."</th>");
    echo ("<th scope=col>"."Enter Amount"."</th>");
    echo ("<th scope=col>"."Msre Desc"."</th>");
    echo ("<th scope=col>"."&nbsp;"."</th>");
    echo ("</tr>");
    
    while ($values = mysql_fetch_array($result))
    {
    	echo ("<form name='addmenu' action ='' method='POST'");
    	echo ("<tr>");
    	echo ("<td>".$values['DEG1']."</td>");
        echo ("<td>");
       	echo ("<input type='textbox' size='3' name='msreval'>");
        echo ("</td>");
        echo ("<td>".$values['DEG2']."</td>");
        echo ("<td>");
        echo ("<input type='submit' value='add' name='submit' size='3'>");
        echo ("</td>");
        echo ("</tr>");
    
    	echo ("</form>");	
    }
    
    	echo ("</table>");
    ?>
    </body>
    </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

    Comment

    • gubbachchi
      New Member
      • Jan 2008
      • 59

      #3
      Hi,

      It helped me a lot. Thank you so much

      Comment

      Working...