0

I am making a form in custom framework in which when user enter 2 numbers e.g start number and ending number . the loop shows all numbers between those numbers . for example if user enter 0300 and 0309 the result will show

0300

0301

0302

0303

0304

0305

0306

0307

0308

0309

but it is showing

0300

301

302

303

304

305

306

307

308

309

Is there a problem with my loop ?

function did_ehmad_sec_submit($editForm) {
$count=0;
$start=$editForm['from_to'];
$end=$editForm['to_range'];
$desc=$editForm['description'];

for ($i=$start;$i<=$end;$i++)
{
$result = mysql_query("INSERT into did_number(did_number, description) VALUES ('$i','$desc')");
}

return $result; 
}
afuzzyllama
  • 6,538
  • 5
  • 47
  • 64
Ehmad Imtiaz
  • 666
  • 5
  • 6

3 Answers3

0

Courtesy : In PHP, how do I add to a zero-padded numeric string and preserve the zero padding?

try using this..

sprintf('%04d', $num);
Community
  • 1
  • 1
Ashwini Agarwal
  • 4,828
  • 2
  • 42
  • 59
0

Whilst you've not tagged your question as being MySQL, this is clearly what's in use.

As such, if you want to store the numbers in the database with a set number of digits (including preceding zeros), one solution would be to make use of the ZEROFILL attribute. (See the MySQL Numeric Type Attributes manual page for more information.)

John Parker
  • 54,048
  • 11
  • 129
  • 129
0

0 is removed automatically. So you can append manually or use ZEROFILL for a numeric column

web2students.com
  • 307
  • 2
  • 16