Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Sep 2010
    Posts
    124
    Thanks
    6
    Thanked 0 Times in 0 Posts

    PHP 4digit no save to mysql problem

    hi again

    i have application im retrewing value from the data base

    database value SCNO as 0043

    whn i writing to the another table table SCNO will go as 43

    but i want to write SCNO as same i retrewing

    fora example 0043 not the 43

    how do i solve this problem

    plzzz provide sample code

  • #2
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    The problem with most number parsing code is it'll treat numbers as numbers, stripping out the "0". You want to keep this treated as a string, so preg_match or strspn/strcspn might be a good idea.

    PHP Code:
        function extractInt($value) {
            
    $num '0123456789';
            
    $pre strcspn($value$num);
            
    $int strspn($value$num$pre);
            return 
    substr($value$pre$int);
        } 
    This (untested) should give you 0043 from 'SCNO0043' or:

    PHP Code:
    function extractInt($value) {
        
    preg_match('/([0-9]*)/'$value$match);
        return 
    $match[1];

    Edit: I've just re-read your post and I might have missed the point. If you're putting 0043 into SQL but it's saving as 43, you have an int field. Make it a varchar field and MySQL should stop stripping the 0.
    Last edited by Lamped; 12-04-2010 at 11:14 AM.
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog

  • #3
    Regular Coder
    Join Date
    Sep 2010
    Posts
    124
    Thanks
    6
    Thanked 0 Times in 0 Posts

    when online update the database from localhost database

    hi again

    i have a application in locally and sever

    i want to do the the application locally ....

    when i online i want to online database update from the local table

    give me any idea for do this plz help me

  • #4
    Regular Coder
    Join Date
    Sep 2010
    Posts
    124
    Thanks
    6
    Thanked 0 Times in 0 Posts

    php mysql record exists problem

    hi again

    hi ,,,, i have a table cost with

    cost no( Unique) , name , and officer in the field names in the table

    i want to insert some records to cost table ....

    i want to check there cost no exists or not before record adding to the table

    example

    in the cost table i have cost no -50

    now i going to insert Cost no-50 ,51 and 52

    it should only insert 51 , 52 because cost no 50 is already there( 50 should not be replace with new record 50 )

    plz give me SQL QUERY for this

    help meeeeeeeeeeeee

  • #5
    Super Moderator
    Join Date
    Feb 2009
    Location
    England
    Posts
    539
    Thanks
    8
    Thanked 63 Times in 54 Posts
    Quote Originally Posted by coolumanga View Post
    hi again

    i have a application in locally and sever

    i want to do the the application locally ....

    when i online i want to online database update from the local table

    give me any idea for do this plz help me
    Depends exactly how you want this to be done.

    PHP: You can write complex PHP to compare and check indexes, update as necessary etc...

    Replication: http://dev.mysql.com/doc/refman/5.0/en/replication.html

    Shell Scripts: I use a script to sync my development copy of websites with my web server. Some of these sites also copy the database with the following linux command:

    Code:
    mysqldump --user=localuser --password=localpassword localdbname | bzip2 -9z | ssh serveruser@serverdomainname "bzip2 -d | mysql --user=serverdbuser --password=serverdbpass serverdbname"
    Which can be made easier with key based, no-password SSH authorisation (look it up).
    lamped.co.uk :: Design, Development & Hosting
    marcgray.co.uk :: Technical blog


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •