project3 Posted February 14, 2008 Share Posted February 14, 2008 $fieldList["`id_dt`"] = sprintf('%02d',"02"); the above gets put into an array an added to db. it will not stay 2 digits. I need the 0 to stay in front and will not stay there. // Insert $sSql = "INSERT INTO `ticket` ("; $sSql .= implode(",", array_keys($fieldList)); $sSql .= ") VALUES ("; $sSql .= implode(",", array_values($fieldList)); $sSql .= ")"; phpmkr_query($sSql, $conn) or die("Failed to execute query at line " . __LINE__ . ": " . phpmkr_error($conn) . '<br>SQL: ' . $sSql); $fieldList["`sid`"] = phpmkr_insert_id($conn); $result = (phpmkr_affected_rows($conn) > 0); $x1 = $fieldList["`sid`"]; Quote Link to comment Share on other sites More sharing options...
effigy Posted February 14, 2008 Share Posted February 14, 2008 I believe this depends on the data type of your field. If it's text, the zero should stay; otherwise, the leading zero will be removed unless you're using the ZEROFILL option. Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 I believe this depends on the data type of your field. If it's text, the zero should stay; otherwise, the leading zero will be removed unless you're using the ZEROFILL option. Field Type Collation Attributes id_dt varchar(11) latin1_general_ci None Quote Link to comment Share on other sites More sharing options...
effigy Posted February 14, 2008 Share Posted February 14, 2008 What does $sSql look like before the insertion? Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 What does $sSql look like before the insertion? see the 02 is in the insert but for some reason the db cuts it off. INSERT INTO `ticket` (`id_dt`,`clientid`,`caselink`,`supportid`,`engineerid`,`additional_email`,`summary`,`time_in`,`time_out`,`jobdesc`,`work`,`cur_status`,`further_action`,`previous_notes`,`equipments_order`,`items_to_order`,`signature`,`company_position`,`bill_status`,`bill_ref`,`case_closed`,`time_in_secs`,`time_out_secs`) VALUES (02,71,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'NO',NULL,NULL,'NO',NULL,NULL,NULL,NULL,'NO',NULL, '- Mins -') Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 What does $sSql look like before the insertion? Just to make sure i changed the field from varchar to text and that did not make a difference. see the 02 is in the insert but for some reason the db cuts it off. INSERT INTO `ticket` (`id_dt`,`clientid`,`caselink`,`supportid`,`engineerid`,`additional_email`,`summary`,`time_in`,`time_out`,`jobdesc`,`work`,`cur_status`,`further_action`,`previous_notes`,`equipments_order`,`items_to_order`,`signature`,`company_position`,`bill_status`,`bill_ref`,`case_closed`,`time_in_secs`,`time_out_secs`) VALUES (02,71,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,'NO',NULL,NULL,'NO',NULL,NULL,NULL,NULL,'NO',NULL, '- Mins -') Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 what is phpmkr? it is probably the one cutting off the 0. look in that code for an is_numeric test. Quote Link to comment Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 it needs to look like this VALUES ('02',71, ... with '..' if you want it treated as a string value Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 what is phpmkr? it is probably the one cutting off the 0. look in that code for an is_numeric test. I took that out and put my own sql in. same result. $this_one = sprintf('%02d',"02"); $con = mysql_connect($host,$dbuser,$dbpass); mysql_select_db($thedb, $con); mysql_query("INSERT INTO `ticket` (id_dt) VALUES ($this_one)"); Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 it needs to look like this VALUES ('02',71, ... with '..' if you want it treated as a string value awesome that worked great! but I guess I cant add ' onto this // Insert $sSql = "INSERT INTO `ticket` ("; $sSql .= implode(",", array_keys($fieldList)); $sSql .= ") VALUES ("; $sSql .= implode(",", array_values($fieldList)); $sSql .= ")"; Quote Link to comment Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 try $fieldList["`id_dt`"] = sprintf("'%02d'","02"); ... Quote Link to comment Share on other sites More sharing options...
project3 Posted February 14, 2008 Author Share Posted February 14, 2008 what happend to the topic solved button? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.