Table cell width <td>problem in php

Discussion in 'PHP' started by jacka, Jul 10, 2008.

  1. #1
    Hi

    I need to display content of a mysql table in a table form to display in a web page.
    Also every table is different with different number of columns.

    The problem I am having is that when there is alot of columns, the table automatically squeezes all the cells to fit in the space provided.
    BUT when it displays data from a table with just a few columns, it gives alot of space to the first column and squeezes the rest.

    by the way the first column is always called "part_number".

    I have tried to set a width='8 px" for example to limit the first column but nothing seems to work.
    How can I :
    a) limit the first column so it does not take any more room that is necessary. (It may be that after I limit the first column width, the second column might misbehave, but I will worry about that when I have fixed the first column problem).
    b)Ideally distribute space equally between columns.


    
    .....
    .width{
    width: 8px;
    
    }
    ...
    
    
    echo ("<table class='table_center' border='1'  >");
    		
    			$arr=array("ipbushes", "mpbushes" , "ifbushes", "mfbushes" ,"msolidbars", "mplates","sp_gr");
    		
    		foreach($arr as  $val)
    {
    
    		
    			$result = mysql_query("   SELECT * FROM $val		 WHERE part_number = '$partnumber'     ");  	
    			
    			if (@mysql_num_rows($result)) {
    			break;
    			}
    	}
    		
    		$row = mysql_fetch_assoc($result);
    		echo $row[1];
    		
    				echo ("<tr class='title'>");
    				
    	// test for first data i.e. part_number			
    $first_data=0;				
    				
    foreach($row as $k=>$v)
    {
    
    if ($first_data==0)
    {
    echo("<td class=\"width\">$k</td>");
    
    } 
    else
    {
    
       echo("<td >$k </td>");
    }
    
    $first_data=$first_data+1;	  
     }
     
    
    Code (markup):
    Thanks for your time
     
    jacka, Jul 10, 2008 IP
  2. Greg Carnegie

    Greg Carnegie Peon

    Messages:
    385
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    For me it looks fine, maybe post your generated HTML code here, as this is more of a HTML CSS question then PHP.
     
    Greg Carnegie, Jul 10, 2008 IP
  3. davegwan

    davegwan Member

    Messages:
    4
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    This is a CSS question.
    Solution:
    add "table-layout: fixed;" to the table class
    add "overflow: hidden;" to the width class

     
    davegwan, Jul 10, 2008 IP
  4. revvi

    revvi Peon

    Messages:
    58
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    in fact, there is something wrong in your css.

    you should set the width in class titlebecause you have set <td> to use that class, like this:

    .title {
    width: 8px;
    }
     
    revvi, Jul 10, 2008 IP