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`"]; Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/ 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. Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467011 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 Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467017 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? Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467020 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 -') Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467040 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 -') Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467049 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. Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467052 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 Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467055 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)"); Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467075 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 .= ")"; Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467078 Share on other sites More sharing options...
Barand Posted February 14, 2008 Share Posted February 14, 2008 try $fieldList["`id_dt`"] = sprintf("'%02d'","02"); ... Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467083 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? Link to comment https://forums.phpfreaks.com/topic/91120-sprintf-will-not-keep-number-2-digits/#findComment-467096 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.