kevinritt Posted May 2, 2009 Share Posted May 2, 2009 Hi, When I display the data, the headings for each column don't line up with results. It looks like the 4 column headings are lining up with the first column and not spanning across 4 columns <table id="poll_table" cellspacing="1" width="300"> <tr> <td id="poll_heading">ID</td><td id="poll_heading">Q1</td><td id="poll_heading">Q2</td><td id="poll_heading">Q3</td> </tr> <? $csql = "select * from poll_poll order by id asc "; $cres = mysql_query($csql); $num_rows = mysql_num_rows($cres); $num_cols = mysql_num_fields($cres); for($i=0; $i < $num_rows; $i++) { echo "<tr>"; $crow = mysql_fetch_array($cres); for($j=0; $j < $num_cols; $j++) { echo "<td colspan=\"4\" bgcolor=\"#ffffff\">"; $field_name = mysql_field_name($cres, $j); echo $crow[$field_name]; echo "</td>"; } echo"</tr>"; } ?> </table> There are 4 fields being called from the database: ID, Q1(current), Q2(affiliation), Q3(rating) Quote Link to comment https://forums.phpfreaks.com/topic/156482-solved-using-colspan-in-echo-statement/ Share on other sites More sharing options...
sasa Posted May 2, 2009 Share Posted May 2, 2009 remove colspan=\"4\" from your echo Quote Link to comment https://forums.phpfreaks.com/topic/156482-solved-using-colspan-in-echo-statement/#findComment-824007 Share on other sites More sharing options...
kevinritt Posted May 2, 2009 Author Share Posted May 2, 2009 remove colspan=\"4\" from your echo Thank you that did it. Can you explain why I wouldn't need the colspan? Quote Link to comment https://forums.phpfreaks.com/topic/156482-solved-using-colspan-in-echo-statement/#findComment-824010 Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Because you already have 4 columns. Say you have 2 columns and you want each to take up 2 columns of space. Then you would set colspan to be 2 for each column. Get it? You can set colspan to be 1. Quote Link to comment https://forums.phpfreaks.com/topic/156482-solved-using-colspan-in-echo-statement/#findComment-824011 Share on other sites More sharing options...
kevinritt Posted May 2, 2009 Author Share Posted May 2, 2009 Got it - thanks Quote Link to comment https://forums.phpfreaks.com/topic/156482-solved-using-colspan-in-echo-statement/#findComment-824013 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.