Jump to content

Changing Color


dudejma

Recommended Posts

Hello. I have this code, which works:

<?php
$con = mysql_connect("localhost","virtu857_invoice","J497");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("virtu857_invoice", $con);

$result = mysql_query("SELECT * FROM invoices") or die("Error: " . mysql_error());

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Client ID</th>
<th>Date Billed</th>
<th>Date Due</th>
<th>Date Paid</th>
<th>Total</th>
<th>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['clientid'] . "</td>";
  echo "<td>" . $row['bill_date'] . "</td>";
  echo "<td>" . $row['due_date'] . "</td>";
  echo "<td>" . $row['paid_date'] . "</td>";
  echo "<td>" . $row['total'] . "</td>";
  echo "<td>" . $row['status'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 

I'm wanting to make the status row change from red if it is: pending, but green if it is: paid.

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/207463-changing-color/
Share on other sites

So something like this:

<?php
$con = mysql_connect("localhost","virtu857_invoice","J497");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("virtu857_invoice", $con);

$result = mysql_query("SELECT * FROM invoices") or die("Error: " . mysql_error());

echo "<table border='1'>
<tr>
<th>ID</th>
<th>Client ID</th>
<th>Date Billed</th>
<th>Date Due</th>
<th>Date Paid</th>
<th>Total</th>
<th>Status</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['id'] . "</td>";
  echo "<td>" . $row['clientid'] . "</td>";
  echo "<td>" . $row['bill_date'] . "</td>";
  echo "<td>" . $row['due_date'] . "</td>";
  echo "<td>" . $row['paid_date'] . "</td>";
  echo "<td>" . $row['total'] . "</td>";
  if($row['status']=="paid") {
    echo "<td style=\"color: green;\">$row[status]</td>";
  }else{
    echo "<td style=\"color: red;\">$row[status]</td>";
  }
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?>

 

Good luck

Link to comment
https://forums.phpfreaks.com/topic/207463-changing-color/#findComment-1084661
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.