Posts Tagged ‘php’

php drop down box list of countries made by foreach array

Sunday, April 19th, 2009

This is some code I wrote to generate a drop down box with all the countries listed in it,  that will preselect the right country if you post the country to it from a previous page. Really helpful if you use it as a control. I have it permanently in my PHP includes folder and just call it any time I need it.eg.:

 <select name=”example”>

<? include ‘../inc/countries.php’ ?>

</select>

Here is countries.php

(more…)

Round your values in PHP using Math Functions (using number_format)

Sunday, April 19th, 2009

To round any number or integer values in PHP it’s simple.number_format is useful function that you can use. It takes 2 values: the $NumberYouWantToFormat and then the number of decimal places you want it to be formatted to. 

$total = 34.128252 echo number_format($total, 2)

This will produce:

34.13 

It’s a simple thing, but really useful.