| | |
How to convert string variable to BIGINT & also to keep leading zeros ??
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2009
Posts: 6
Reputation:
Solved Threads: 0
Hello,
I need to convert a string variable to BIGINT and store it into the mysql database. I have used settype() but its removing my leading zero in the string.
For example,
The above code removes 00 (leading zeros).Can someone help me how to keep the zeros along with variable type as float??
Help would be appreciated
Thanks.
I need to convert a string variable to BIGINT and store it into the mysql database. I have used settype() but its removing my leading zero in the string.
For example,
PHP Syntax (Toggle Plain Text)
$new_id1="12"; $new_id2="345"; $zero="0"; $id="{$zero}{$zero}{$new_id1}{$new_id2}"; settype($id,"float"); echo $id; output: 12345 // Instead of getting 0012345
The above code removes 00 (leading zeros).Can someone help me how to keep the zeros along with variable type as float??
Help would be appreciated
Thanks.
Last edited by ramsri05; Aug 15th, 2009 at 4:34 am.
Numeric datatypes will never have leading zeros. You could add a dummy number to the front and just remove with substr when outputting it.
php Syntax (Toggle Plain Text)
$new_id1="12"; $new_id2="345"; $zero="0"; $id="1{$zero}{$zero}{$new_id1}{$new_id2}"; settype($id,"float"); echo $id; // outputs 10012345 echo"<br>"; $id = substr($id,1);//remove dummy number echo $id; // outputs 0012345
Last edited by buddylee17; Aug 15th, 2009 at 10:46 am.
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
•
•
Join Date: Jul 2009
Posts: 6
Reputation:
Solved Threads: 0
Thanks buddylee17,
Well, I wanted to add leading zero in the numeric datatype only. because I should insert it into MySql database BIGINT data field.
Is there any way to insert the numeric/string value with leading zero into MYSQL BIGINT field ? If I insert a string of "0123456" this BIGINT field removes leading 0 and showing only 123456. how to make it show this 0 without enabling unsigned zerofill option? HELP pls !!
Well, I wanted to add leading zero in the numeric datatype only. because I should insert it into MySql database BIGINT data field.
Is there any way to insert the numeric/string value with leading zero into MYSQL BIGINT field ? If I insert a string of "0123456" this BIGINT field removes leading 0 and showing only 123456. how to make it show this 0 without enabling unsigned zerofill option? HELP pls !!
•
•
•
•
Thanks buddylee17,
Well, I wanted to add leading zero in the numeric datatype only. because I should insert it into MySql database BIGINT data field.
Is there any way to insert the numeric/string value with leading zero into MYSQL BIGINT field ? If I insert a string of "0123456" this BIGINT field removes leading 0 and showing only 123456. how to make it show this 0 without enabling unsigned zerofill option? HELP pls !!
It only depends on whether you quote the value in the MySQL query or not.
If you quote a value, it is treated as a string. However, MySQL will automatically convert that to the type of the column.
I don't think you can place 0 in front of a bigint column unless you specify zerofill.
If you have phpmyadmin just play around with the values and storage type of the table to make sure.
www.fijiwebdesign.com - web design and development and fun
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
Cpanel Email - Let users Register email accounts on your website upon registration
Ajax Chat - Fully browser based chat!
![]() |
Similar Threads
- Convert string into string variable (VB.NET)
- Convert string variable into form object (VB.NET)
- Convert string variable into form object in VB6 (Visual Basic 4 / 5 / 6)
- convert string to double, and result is string again (Java)
Other Threads in the PHP Forum
- Previous Thread: New Social Networking Site
- Next Thread: php and emailform
| Thread Tools | Search this Thread |
apache api array beginner binary broken cache cakephp checkbox class cms code codingproblem cron curl customizableitems database date display dynamic echo email error errorlog file files filter folder form format forms forum function functions gc_maxlifetime global google headmethod host href htaccess html image include insert ip javascript joomla limit link login mail malfunctioning memmory memory menu mlm multiple mysql nodes oop parameter parsing paypal pdf php phpmysql problem query radio random recursion recursiveloop remote script search select server sessions sms snippet source space sql static survey syntax system table trouble tutorial up-to-date update upload url validator variable video web youtube






