0

this is my PHP code:

$query="SELECT name, surname, address FROM employee";
$results = mysql_query($query);

while ($row = mysql_fetch_assoc($results)) {
echo '<tr>';
foreach($row as $field) {
    echo '<td class="element">' . htmlspecialchars($field) . '</td>';
}
echo '</tr>';

And this is my CSS:

.element{
    color:red;  
}

But fields displayed in my HTML page aren't red. Why it doesn't work?

I already tried with

 echo "<td class='element'>" . htmlspecialchars($field) . "</td>";

and

 echo '<td class=\"element\">' . htmlspecialchars($field) . "</td>";

but with no success.

Notash
  • 47
  • 1
  • 4
  • 5
    use your browser's dom inspector to see what rules ARE being applied. Maybe you've got a css syntax error somewhere earlier that's killing your `red` rule, or there's a `!important` override somewhere. – Marc B Nov 05 '14 at 21:31
  • Get to know the tools of the trade: Chrome developer tools or Firebug for Firefox. Inspect the element and work from there. These tools will tell if the rule is applied and what other rules are applied – Jon P Nov 05 '14 at 21:32
  • 3
    Please, [don't use `mysql_*` functions](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), They are no longer maintained and are [officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). Learn about [prepared statements](http://en.wikipedia.org/wiki/Prepared_statement) instead, and use [PDO](http://us1.php.net/pdo) or [MySQLi](http://us1.php.net/mysqli). [This article](http://php.net/manual/en/mysqlinfo.api.choosing.php) will help you decide. – Jay Blanchard Nov 05 '14 at 21:36

2 Answers2

0

then try this.

echo '<td style="color:red">' . htmlspecialchars($field) . '</td>';

even this 1 below shold work

echo '<td class="element">' . htmlspecialchars($field) . '</td>'; // for this just dont remove your css class

you just copy and paste to replace your code. and remove that class in css the issue of mysl_ does not affect that not to display, i am using latest php engine and they work fine, even though we need to change.

Fas M
  • 429
  • 2
  • 11
0

I suggest to specify element in your css.

td.element{
    color:red;  
}

Also it's a good idea to give your "tr" an ID "tr id="myTR"...

#myTR td.element{
    color:red;  
}
SergeDirect
  • 2,019
  • 15
  • 20