webguync Posted August 28, 2009 Share Posted August 28, 2009 Hi, I have some code which displays data from MySQL into and html table. What I am wanting to do is to add some CSS to some of the columns (<td>), to control their width, but cannot figure out how to do this with my current code. I can't just add the CSS to (td) because I don't want to set the same width to all of the columns. I will need to add a class(td.number). I may need to change the PHP configuration, but not sure how. My current code is: print "<table class='delete'><tr><th> # </th>"; foreach( $fields AS $key => $val ) print "<th>$val[0]</th>"; print "</tr>"; if ( mysql_num_rows( $result_query ) > 0 ) { $rownumber = 1; while ( $rows_query = mysql_fetch_assoc( $result_query ) ) { print "<tr>\n"; print "<td>$rownumber.</td>"; print "<input type=\"hidden\" name=\"keys[]\" value=\"{$rows_query[$idfield]}\">"; foreach( $fields AS $key => $value ) { if ( $value[1] == "textfield" ) echo "<td><input name=\"{$key}[{$rows_query[$idfield]}]\" type=\"text\" name=\"status\" id=\"status\" value=\"" . ( isset( $rows_query["$key"] )?htmlspecialchars( $rows_query["$key"] ):"" ) . "\"></td>\n"; elseif ( $value[1] == "checkbox" ) { echo "<td><input name=\"{$key}[{$rows_query[$idfield]}]\" type=\"checkbox\" name=\"status\" id=\"status\ value=\"1\"" . ( !empty( $rows_query["$key"] )?" checked=\"checked\"":"" ) . "></td>\n"; } elseif ( $value[1] == "textarea" ) { echo "<td> <textarea name=\"{$key}[{$rows_query[$idfield]}]\" cols=\"45\" rows=\"5\" wrap=\"virtual\">" . ( isset( $rows_query["$key"] )?htmlspecialchars( $rows_query["$key"] ):"" ) . "</textarea></td>\n"; } elseif ( $value[1] == "delete_checkbox" ) { echo "<td id=\"CheckBox\"><input name=\"delete[{$rows_query[$idfield]}]\" type=\"checkbox\" value=\"1\"></td>\n"; } } print "</tr>\n"; $rownumber++; } } else echo "<span class='status'>No result in query table ...</span>"; print "</table>\n"; Link to comment https://forums.phpfreaks.com/topic/172290-need-to-control-a-td-column-with-css-within-php-code/ Share on other sites More sharing options...
ReKoNiZe Posted August 28, 2009 Share Posted August 28, 2009 For any of the TD's you want to play with, just do something like: <td class="Myclass"> And for the CSS use td.Myclass {} Link to comment https://forums.phpfreaks.com/topic/172290-need-to-control-a-td-column-with-css-within-php-code/#findComment-908402 Share on other sites More sharing options...
webguync Posted August 28, 2009 Author Share Posted August 28, 2009 yea, I understand the CSS part, but when I try something like below, the css will control all of the text fields, and I only want to control a few columns. echo "<td class='number'><input name=\"{$key}[{$rows_query[$idfield]}]\" type=\"text\" name=\"status\" id=\"status\" value=\"" . ( isset( $rows_query["$key"] )?htmlspecialchars( $rows_query["$key"] ):"" ) . "\"></td>\n"; Link to comment https://forums.phpfreaks.com/topic/172290-need-to-control-a-td-column-with-css-within-php-code/#findComment-908416 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.