i have real estate site where i can search the location,state,city,bedrooms .all these details get in a table but i want to change the color of the rows and cols of the search result table .how i have to proceed. i ahve used php to get serach result

Dani AI

Generated

Quick, practical summary for : you can style the search-results table entirely with CSS, or combine CSS with a tiny bit of PHP when you generate each row. was right to suggest alternating row classes; ’s FrontPage steps will work but often insert inline styles. Prefer CSS classes or modern selectors so styling stays in one place and is easier to maintain.

CSS-first (clean, simple)

/* zebra rows + hover */
table.results { border-collapse: collapse; width: 100%; }
table.results tr:nth-child(even) { background-color: #f8f8f8; }
table.results tr:nth-child(odd)  { background-color: #ffffff; }
table.results tr:hover { background-color: #fff7cc; }

/* highlight a specific column (eg. 3rd column = price) */
table.results td:nth-child(3) { background-color: #eef6ff; }

/* or use colgroup with classes */
col.col-price { background-color: #eef6ff; }

Server-side (robust, works on old browsers)

<?php
echo '<table class="results"><tbody>';
$row = 0;
while ($r = mysqli_fetch_assoc($res)) {
  $class = ($row % 2) ? 'odd' : 'even';
  echo '<tr class="' . $class . '">';
  echo '<td>' . htmlspecialchars($r['title']) . '</td>';
  echo '<td>' . htmlspecialchars($r['bedrooms']) . '</td>';
  echo '<td>' . htmlspecialchars($r['price']) . '</td>';
  echo '<td>' . htmlspecialchars($r['location']) . '</td>';
  echo '</tr>';
  $row++;
}
echo '</tbody></table>';
?>

Quick tips: keep color contrast high for readability; avoid using color alone to convey meaning; add :focus styles or actual links/buttons if rows are clickable so keyboard users can navigate; use @media print to disable heavy backgrounds when printing. If supporting very old browsers, use the PHP class toggle as a fallback for :nth-child selectors.

Recommended Answers

All 5 Replies

You can use CSS to color HTML elements. Let me know where to start: how much to you currently know about CSS?

yes i m good in css i wnat my table to be like this site

If you know PHP and CSS, then what is the question? Simply define two CSS declarations, one for each row color, and apply the CSS class on every other row as you build the table.

i have real estate site where i can search the location,state,city,bedrooms .all these details get in a table but i want to change the color of the rows and cols of the search result table .how i have to proceed. i ahve used php to get serach result

Do you know much about HTML ? If so then i'd be willing to help.
Also, are you using a certain web design program to make that table ? I ask because if its Front Page you can do the following. Right click the cell. Click on Cell Properties from the list. Near the bottom of the new window it should say Background. If you need diagrams ask and I will post them up

I have attached a zip file that includes 3 steps on how to change a cell colour in Front Page. To change the colour on a number of cells do the same but highlight the cells you want to change.

Ollie

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.