Jump to content

different td rows how to get?


$php_mysql$

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.