php - Add zeros at beginning of a number if it is small than 1000 -
i have sql query
select count(*) tot_std `login` `login_account_type` = 'student'
the output of query 9.
what want add:
- three zeros if number small 10, 0009.
- two zeros if number small 99, 0099,
- one 0 if number smaller 999, 0999.
- if number equal or greater 1000, don't add zero.
note using php codeigniter , mysql project.
please help.
try below code
in query, can like
select lpad(count(*),4,'0') tot_std login login_account_type = 'student'
in php
$your_value = 9; $your_value = str_pad($your_value,4,'0', str_pad_left); echo $your_value;
str_pad()
function add leading zeros. second parameter
shows total number. need thousands, add 4. 3rd parameter
represent character added @ beginning. fourth parameter
side need add zero
Comments
Post a Comment