$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>"; Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 any help? Quote Link to comment 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..? Quote Link to comment 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>"; } Quote Link to comment 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 Quote Link to comment 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 Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
$php_mysql$ Posted August 6, 2011 Author Share Posted August 6, 2011 sorted very thankful mate :-) Quote Link to comment 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.