![]() |
Change integer value if first digit is zero(0) - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Change integer value if first digit is zero(0) (/showthread.php?tid=49377) |
Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [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 Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [eluser]louisl[/eluser] Make the var a string as 0xx as integer will drop the 0 as it's a number Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [eluser]phparif[/eluser] @louisl, I use this $arr = (string)074052; but result is same previous[`StudentId` = 30762] Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [eluser]louisl[/eluser] $rol = '07405l2'; Try that, I'm assuming your db student Id field is varchar Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [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'); } Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [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'; Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [eluser]phparif[/eluser] Thanks..... Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [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). Change integer value if first digit is zero(0) - El Forum - 02-17-2012 [eluser]phparif[/eluser] Again thanks of all. |