i would like to display numbers 0000 - 9999 and am having a problem. heres my code <?php $num = 0000; while ($num != 10000) { echo $num; $num++; } ?> this lists all the numbers. however it list it like: 0 1 2 3 and i need it to list it like 0000, 0001, 0002, 0003 and so on. any help would be appreciated. thanks.
that worked only for 0000 it then didnt show 0001, 002 all the wasy to 0999 those didnt show up at all.
This works fine for me (note I changed it to 20 and added the <br /> $num = 0000; while ($num != 20) { echo str_pad($num, 4, '0',STR_PAD_LEFT).'<br />'; $num++; } PHP:
try this then... for($num=0;$num<10000;$num++) { echo str_pad($num, 4, "0", STR_PAD_LEFT).'<br />'; }
this worked great, untill i tried to enter these nums into the database, they then turned back into the single digits again while ($num != 10000) { $num = str_pad($num, 4, '0',STR_PAD_LEFT); mysql_query("INSERT into table (id, num) VALUES ('null', '$num')", $l) or die(mysql_error()); $num = $num + ; } PHP: i need it to hold those 4 digits into the database. any help????
You could change the column type to be varchar rather than the number format you have. It will never hold it otherwise