Change integer value if first digit is zero(0) |
[eluser]phparif[/eluser]
Please any one help me about : If i start a integer number with 0(zero), its value is change when execute, suppose if i execute this active record $rol = 074052; $this->db->set('AdviserId', 'A00002') ->where('DepartmentId', 'C06') ->where('StudentId',$rol) ->update('student_info'); it generate a query like this UPDATE `student_info` SET `AdviserId` = 'A00002' WHERE `DepartmentId` = 'C06' AND `StudentId` = 30762; in my active record i put StudentId = 074052, but in generated query why `StudentId` = 30762
[eluser]louisl[/eluser]
Make the var a string as 0xx as integer will drop the 0 as it's a number
[eluser]louisl[/eluser]
$rol = '07405l2'; Try that, I'm assuming your db student Id field is varchar
[eluser]phparif[/eluser]
Actually Roll no is posted by user which is in textBox(txtextra) separated by coma(Example: 074051,074052,074053). when submit it call a function like this function SelectAdviser(){ $data = explode(",",$this->input->post('txtextra')); $this->db->set('AdviserId', 'A00002') ->where('DepartmentId', 'C06') ->where_in('StudentId',$data) ->update('student_info'); } Now generated query all is ok, but roll is generate unexpected number, as a result of prefix 0(zero). I try below two way but result is same : #1) function SelectAdviser(){ $data = explode(",",$this->input->post('txtextra')); $data = array_map('strval',$data); $this->db->set('AdviserId', 'A00002') ->where('DepartmentId', 'C06') ->where_in('StudentId',$data) ->update('student_info'); } #2) function SelectAdviser(){ $data = explode(",",$this->input->post('txtextra')); foreach ($data as $index => $val) $data[$index] = (string) $val; $this->db->set('AdviserId', 'A00002') ->where('DepartmentId', 'C06') ->where_in('StudentId',$data) ->update('student_info'); }
[eluser]aquary[/eluser]
I run a little code to test, and it seems to be a part in active record escaped/protected the 0xxxxx pattern. EDIT: errr.... no, it's PHP engine convert those number. Maybe PHP treats the 0xxxx pattern as a hex or something similar back to integer. EDIT: It's OCTAL number www.php.net/manual/en/language.types.integer.php BUT, anyway, since the data came from input/textarea with comma as a separator, this code works fine: Code: $val='074051,074052,074053';
[eluser]louisl[/eluser]
Hmm that is weird because if txtextra is a textbox with comma seperated values then it's a string to start with. So you were essentially doing #3 so it does look like active record is doing a conversion. eg:- Code: 1).
|
Welcome Guest, Not a member yet? Register Sign In |