Jump to content

sprintf will not keep number 2 digits


project3

Recommended Posts

 

$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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.