xcandiottix Posted September 22, 2010 Share Posted September 22, 2010 I have a db with entries as follows: A001 A002 A003 I would like to loop thru these and print them on screen. Instead of doing: echo A001 echo A002 echo A003 I'd like to find a better way since this database will scale up in the future and may get to A999. Is there a way to increment with leading placeholder zeros? for($x=0 ; $x < mysql_num_rows($myresult) ; $x++){ echo $row['A'.##increment here##']; } Thanks! Link to comment https://forums.phpfreaks.com/topic/214064-increment-with-leading-zeros/ Share on other sites More sharing options...
ShibSta Posted September 22, 2010 Share Posted September 22, 2010 I haven't tested it but you could try something like: for($x=0 ; $x < mysql_num_rows($myresult); $x++){ echo $row['A' . sprintf("%03d",$x)]; } However, to loop through MySQL results you could just do: while($row = $myresult) var_dump($row); Link to comment https://forums.phpfreaks.com/topic/214064-increment-with-leading-zeros/#findComment-1113936 Share on other sites More sharing options...
xcandiottix Posted September 22, 2010 Author Share Posted September 22, 2010 yip, that worked great, thanks! Link to comment https://forums.phpfreaks.com/topic/214064-increment-with-leading-zeros/#findComment-1113948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.