开发者

Pulling in a number from MySQL database & WordPress custom field and multiplying/dividing them in PHP

I'm currently trying to pull in two numbers (1 from a MySQL Database and开发者_运维技巧 another from a WordPress custom field) and multiply them.

E.g: <?php echo ($data['price'] / 2) * NUMBER-FROM-DATABASE ;?>

Can I pull in from the Database in a normal way and place the code in this formula or do I have to do something else with it?

Thanks in advance,

Barry


What you wrote would work~ I would recommend:

<?php echo '$'.number_format(($data['price']/2) * $row['number_from_db'],2)?>

If you are concerned the value from DB might not be a int/float and could cause an error, type cast it:

<?php echo '$'.number_format(($data['price']/2) * (int)$row['number_from_db'],2)?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜