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

Read More

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

Related posts

Leave a Reply

1 comment

  1. 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)?>