affc Posted January 29, 2009 Share Posted January 29, 2009 Hello, This code used to work by placing a "0" infront of a number if it was only between 1-9 it would make it 01-09. Now it simply puts a 1 infront of it so 11-19 which isn't what Im after. Was there a code upgrade I missed? Thanx in advance $sql6="SELECT * FROM $tbl_name7"; $result6=mysql_query($sql6); $count3=mysql_num_rows($result6); $COUNTS =$count3+1; $number=$_GET['No']; $THISNUMBER = substr("$COUNTS".$number, -2); Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/ Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 works lovely with numbers. <?php $num="1234567789"; echo " ".substr($num,0,2).""; ?> <?php $num['redarrow']="1234567789"; echo " ".substr($num['redarrow'],0,2).""; ?> what the "" << for then? Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-749985 Share on other sites More sharing options...
redarrow Posted January 29, 2009 Share Posted January 29, 2009 $THISNUMBER = substr("$COUNTS".$number, -2); to $THISNUMBER = substr($COUNTS.$number, -2); and try agin. works perfect. <?php $num['redarrow']="1234567789"; $add="910"; echo " ".substr($num['redarrow'].$add,-3).""; ?> Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-749988 Share on other sites More sharing options...
affc Posted January 30, 2009 Author Share Posted January 30, 2009 Hi thank you for the replied but that doesn't work for what I am after. I have a GET function that will get a number such as "1" from the address bar. I want to add a 0 at the beginning and so on up to 9 and any number after that is left alone but limited to only 2 digit numbers for the result. I cant seem to get it to put a 0 at the start anymore so 1 becomes 01 and so on. Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-750450 Share on other sites More sharing options...
trq Posted January 30, 2009 Share Posted January 30, 2009 $sql6="SELECT * FROM $tbl_name7"; $result6=mysql_query($sql6); $count3=mysql_num_rows($result6); $COUNTS =$count3+1; $number=$_GET['No']; $THISNUMBER = sprintf("%02d", $number); Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-750462 Share on other sites More sharing options...
affc Posted January 30, 2009 Author Share Posted January 30, 2009 Ah that works but I want it so that if there is no No in the Address bar it will use the $COUNT result instead? Is this possible, my script worked fine last year but this year seems not to be working. Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-750469 Share on other sites More sharing options...
affc Posted January 30, 2009 Author Share Posted January 30, 2009 Ah using your Code I did get it to work. Just used this at the end of your code: if(empty($number)){ $THISNUMBER=$COUNTS; } Works a charm thank you for your help Link to comment https://forums.phpfreaks.com/topic/143025-substr-not-working-with-numbers/#findComment-750472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.