Ryan Shmera Ryan Shmera - 2 months ago 6
jQuery Question

Bold table column generated from php

I am trying to bold the content of the last column of my table, not sure how to select those key values and apply a bold, very new with jquery.

<?php
$items = array(
array("City" => "Dalas","Age" => "47", "Name" => "Janet Fuller", "Address" => "445 Upland Pl.", "Status" => "Trial"),
array("City" => "Lyon", "Age" => "38", "Name" => "Andrew Heiniger", "Address" => "347 College Av.", "Status" => "Active"),
array("City" => "Dallas", "Age" => "43", "Name" => "Susanne Smith", "Address" => "2 Upland Pl.", "Status" => "Active"),
array("City" => "Paris", "Age" => "25", "Name" => "Sylvia Steel", "Address" => "269 College Av.", "Status" => "Suspended"),
array("City" => "San Francisco", "Age" => "7", "Name" => "James Peterson", "Address" => "231 Upland Pl.", "Status" => "Active"),
array("City" => "Oslo", "Age" => "42", "Name" => "Robert Ott", "Address" => "503 Seventh Av.", "Status" => "Trial")
);
?>

<?php if (count($items) > 0): ?>
<table>
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($items))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>

Answer

Just use css:

#myTable td:last-child {
  font-weight: bold;
}
<table id="myTable">
  <thead>
    <tr>
      <th>first</th>
      <th>last</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>first</td>
      <td>last</td>
    </tr> 
    <tr>
      <td>first</td>
      <td>last</td>
    </tr> 
  </tbody>
</table>