...

View Full Version : PHP 4digit no save to mysql problem



coolumanga
12-04-2010, 07:39 AM
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

Lamped
12-04-2010, 11:11 AM
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.


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:



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.

coolumanga
12-06-2010, 04:23 AM
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

coolumanga
12-06-2010, 08:25 AM
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

Lamped
12-06-2010, 10:11 AM
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:



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).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum