PHP table 中的货币格式从数据库中获取价格

Money format in PHP table taking the price from a Database

在这个Image you can see how my table currently displays, with the price of the items being collected from a mysql database, and displays just as '500' or how ever much the item is I want it to display '£500' I have tried number format and I have tried with and without a locale but still get the same error 目前将其与 $ 一起用于测试*

感谢您的帮助! :D

    include 'db_connection.php';

    $conn = OpenCon();

    echo "Connected Successfully";
 setlocale(LC_MONETARY, 'en_US');

        $sql = "SELECT * FROM Product, Manufacturer Where Product_ID = Manufacturer_ID";
        $result = $conn->query($sql);
        if ($result->num_rows > 0){
            echo "<table>
                <tr>
                    <th>Product ID</th>
                    <th>Name</th>
                    <th>Product Description</th>
                    <th>Price</th>
                    <th>Image</th>
                    <th>Manufacturer Name</th>
                    </tr>";
            while($row = $result->fetch_assoc()){
                echo "<tr>
                    <td>".$row["Product_ID"]."</td>
                    <td>".$row["Name"]."</td>
                    <td>".$row["Product_Description"]."</td>
                    <td>" '$'.number_format(floatval($row["ProductPrice"]));."</td>
                    <td><img src='images/".$row['ProductImage']."'></td>
                    <td>".$row["ManufacturerName"]."</td>
                </tr>"; 
            }
            echo "</table>";
        } else {
            echo "0 results";
            }

        $conn->close();

您收到语法错误是因为您在两个字符串(包含 <td> 的双引号字符串和包含 [= 的单引号字符串)之间缺少 . 13=]).

您不需要为您的货币符号创建新的字符串,只需将它添加到您已经回显的字符串中即可:

echo "<tr>
    [...]
    <td>&pound;" . $row["ProductPrice"] . "</td>
    [...]
</tr>";