Re: Zeros get striped off my db entrees.... how to stop...
| From: | Richard Lynch | Date: | Tue, 30 Jan 2001 08:15:36 +0000 |
| Subject: | Re: Zeros get striped off my db entrees.... how to stop... | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-37263@lists.php.net to get a copy of this message | ||
> Ok, I have a string of bits that I combine to store as the privilege level
> for our users.... it is 5 chars long "12345", and the default is "00000"
> this would be the most basic user. now, when there is a non 0 number at
the
> front.... it works.... and every thing is cool.... but, even though the
> field is set as CHAR 5, if the privs number is set to 00110, it is stored
in
> the DB as 110.... or at least that is how it is retrieved.... in
> PHPmyAdmin.... it shows up as 00110....
>
> so anyway, somewhere it is stripping the leading 0's off the number, and I
> need to know why and how to fix that.....
PHP auto-converts data on an as-needed basis. It probably is stripping the
leading 0's off only when you print, and when you attempt to compare them
using ==.
[Though I don't think the == part is going to hurt you...]
For output, you can use something not unlike:
printf("%05s", $foo);
[Only I probably got the 05 part wrong -- I usually do until I go re-read
http://php.net/printf]
For your tests, you can use strcmp rather than == if that seems to be going
wrong.
--
Visit the Zend Store at http://www.zend.com/store/
Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm
Volunteer a little time: http://chatmusic.com/volunteer.htm