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! Quote Link to comment 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); Quote Link to comment Share on other sites More sharing options...
xcandiottix Posted September 22, 2010 Author Share Posted September 22, 2010 yip, that worked great, thanks! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.