$php_mysql$ Posted August 6, 2011 Share Posted August 6, 2011 here is my php coding and i got these 2 classes in css, how do i get it in my coding? .row1 { background-color: #e7eaef; cursor:pointer; } .row2 { background-color: #cacdd3; cursor:pointer; } echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\">"; if(!count($Post)){ print 'no records'; }else{ echo "<tr class=\"rowhead\">"; echo "<td ><b>Image </b></td>"; echo "<td ><b>Title!</b></td>"; echo "<td ><b>Type</b></td>"; echo "<td ><b>State </b></td>"; echo "<td ><b>City/Town</b></td>"; echo "<td ><b>Posted</b></td>"; echo "</tr>"; foreach($Post as $p){ echo "<tr class=\"1row\">"; if(empty($p['image'])){ echo "no image"; }else{ echo "<td><a href=\"".$p['image']."\"><img src=\"".$p['image']."\" width=\"50px\" height=\"50\" alt=\"$image\"/></a></td>"; } echo "<td><a href=\"details.php?name=$Name&ID=".$p['id']."\">".$p['title']."</a></td>"; echo "<td>".$p['adtype']."</td>"; echo "<td>".str_replace('_', ' ', $p['state'])."</td>"; echo "<td>".$p['location']."</td>"; echo "<td>".$p['time']."</td>"; echo "</tr>"; } echo "</table>"; Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/ Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 any help? Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253312 Share on other sites More sharing options...
AyKay47 Posted August 6, 2011 Share Posted August 6, 2011 add the class to whatever tag you want it to be applied to..? Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253315 Share on other sites More sharing options...
Psycho Posted August 6, 2011 Share Posted August 6, 2011 Added logic to alternate between row1 and row2. Also cleaned up the code. Change the header cells from TD to TH (they will be bold automatically) echo "<table border=\"0\" cellpadding=\"5\" cellspacing=\"2\" width=\"100%\">"; if(!count($Post)) { print 'no records'; } else { echo "<tr class=\"rowhead\">\n"; echo " <th>Image</th>\n"; echo " <th>Title!</th>\n"; echo " <th>Type</th>\n"; echo " <th>State </th>\n"; echo " <th>City/Town</th>\n"; echo " <th>Posted</th>\n"; echo "</tr>\n"; $rowClass = ''; foreach($Post as $p) { $rowClass = ($rowClass!='row1') ? 'row1' : 'row2'; $link = "<a href=\"details.php?name={$Name}&ID={$p['id']}\">{$p['title']}</a>"; $state = str_replace('_', ' ', $p['state']); if(empty($p['image'])) { $image = 'no image'; else { $image = "<a href=\"{$p['image']}\"><img src=\"{$p['image']}\" width=\"50px\" height=\"50\" alt=\"{$image}\"/></a>"; } echo "<tr class=\"{$rowClass}\">\n"; echo " <td>{$image}</td>"; echo " <td>{$link}</td>"; echo " <td>{$p['adtype']}</td>\n"; echo " <td>{$state}</td>\n"; echo " <td>{$p['location']}</td>\n"; echo " <td>{$p['time']}</td>\n"; echo "</tr>\n"; } echo "</table>"; } Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253320 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 its giving me no records message any idea? tho there are 2 records Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253430 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 sorry my bad its working fine just one } was missing :-) thanks soo much Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253438 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 ah one issue every time there is a new entry then the old entris image displays along with a "/>"/> what could be that? Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253448 Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 sorted very thankful mate :-) Link to comment https://forums.phpfreaks.com/topic/244045-different-td-rows-how-to-get/#findComment-1253454 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.