[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 195
  • Last Modified:

How do I add a Dollar Sign to this Code?

Two more quick items for today:
Using this script to product a report I like to format the field "Sale Price" to include a Dollar sign.  It currently returns this:

Item Number Starting Date Ending Date Sale Price
COCO1G 2014-08-27 05:00:00 2014-08-31 23:59:00 37.85
COCO32Z 2014-08-27 05:00:00 2014-08-31 23:59:00 20.45
COCO8Z 2014-08-27 05:00:00 2014-08-31 23:59:00 7.75
COCOBALM14Z 2014-08-27 05:00:00 2014-08-31 23:59:00 19.85
COCOBALM32Z 2014-08-27 05:00:00 2014-08-31 23:59:00 36.65


$result = mysqli_query($con,"SELECT ItemNumber, StartingDate, EndingDate, SalePrice FROM biomas.ITProductSale where StartingDate >= CURDATE()");

 echo "<table border='1'>
 <tr>
 <th>Item Number</th>
 <th>Starting Date</th>
 <th>Ending Date</th>
 <th>Sale Price</th>
 </tr>";

 while($row = mysqli_fetch_array($result))
   {
   echo "<tr>";
   echo "<td>" . $row['ItemNumber'] . "</td>";
   echo "<td>" . $row['StartingDate'] . "</td>";
   echo "<td>" . $row['EndingDate'] . "</td>";
   echo "<td>" . $row['SalePrice'] . "</th>";
   echo "</tr>";
   }
 echo "</table>";
0
Scott Johnston
Asked:
Scott Johnston
2 Solutions
 
GaryCommented:
Just add it

echo "<td>$" . $row['SalePrice'] . "</th>";

Open in new window

0
 
Daniel ReynoldsSoftware Applications Developer / IntegratorCommented:
a rather simple way without attempting any formatting of the return value is to change the html you are sending.

while($row = mysqli_fetch_array($result))
    {
    echo "<tr>";
    echo "<td>" . $row['ItemNumber'] . "</td>";
    echo "<td>" . $row['StartingDate'] . "</td>";
    echo "<td>" . $row['EndingDate'] . "</td>";
    echo "<td> $" . $row['SalePrice'] . "</th>";
    echo "</tr>";
    }
  echo "</table>";
0
 
Scott JohnstonSystems ConsultantAuthor Commented:
I appreciate your eyes today.
0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now