【问题标题】:Money format in PHP table taking the price from a DatabasePHP 表中的货币格式从数据库中获取价格
【发布时间】:2018-05-12 18:18:40
【问题描述】:

Image 中,您可以看到我的表格当前的显示方式,以及从 mysql 数据库中收集的商品价格,并显示为“500”或我希望它显示多少商品“ 500 英镑我尝试过数字格式,我尝试过使用和不使用语言环境,但仍然得到相同的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();

【问题讨论】:

    标签: php mysql money-format


    【解决方案1】:

    您收到语法错误,因为您在两个字符串(包含&lt;td&gt; 的双引号字符串和包含$ 的单引号字符串)之间缺少.

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

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

    【讨论】:

    • 谢谢,我只是使用了我找到的东西,但是当它允许我时,它会标记为答案,非常感谢:D:D
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-09-08
    • 1970-01-01
    • 2012-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多