How do I add a Dollar Sign to this Code?

Posted on 2014-08-26
Last Modified: 2014-08-26
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'>
 <th>Item Number</th>
 <th>Starting Date</th>
 <th>Ending Date</th>
 <th>Sale Price</th>

 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>";
Question by:Scott Johnston
    LVL 58

    Accepted Solution

    Just add it

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

    Open in new window

    LVL 17

    Assisted Solution

    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>";

    Author Closing Comment

    by:Scott Johnston
    I appreciate your eyes today.

    Featured Post

    What Is Threat Intelligence?

    Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

    Join & Write a Comment

    As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now