Jump to content

Leading zeros are being cutoff....


mellis95

Recommended Posts

I have a problem with PHP seemingly dropping leading zeros from my variables... I am displaying ICD9 codes, which sometimes have leading zeroes, sometimes have two decimal places, sometimes just one decimal place, which is why I decided that storing as char() would probably work the best for this. The data is storing exactly as I need it in the table, but when I display it on a page, it drops the leading zeros. Here is what I have

 

I have the following result in a mysql query:

mysql> select code, description from tbl_icd9 WHERE code like '%078%';
+--------+--------------+
| code   | description  |
+--------+--------------+
| 078.12 | PLANTAR WART |
+--------+--------------+
1 row in set (0.00 sec)

 

I have the following on my display page:

 

$query = "SELECT  code, description FROM tbl_icd9 where code like %$var% order by code";  

The value of $var is "078" , so the query is exactly the same as what I did on the command line. However the following outputs $code as "78.12" instead of "078.12".

$numresults= mysql_query($query);
$numrows=mysql_num_rows($numresults);
// next determine if s has been passed to script, if not use 0
  if (empty($s)) {
  $s=0;
  }
    print "\n<table>\n<tr>\n" .
"\n\t<th></th>" .
"\n\t<th>Code</th>" .
"\n\t<th>Description</th>" .
"\n</tr>";
// get results
  $query .= " limit $s,$limit";
  $result=mysql_query($query);
  $code_array=mysql_fetch_array($result);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$code=mysql_result($result,$i,"code");
$description=mysql_result($result,$i,"description");
print "\n<tr>";
print 	"<td><a href=\"../poc/use_code.php?pocid=$eid&code=$code_array["code"]\">Select</a></td>
<td>$code_array[code]</td>
<td>$description</td>";
print "\n</tr>";

$i++;
}
print "\n</table>\n";

 

I can't find anything that should be trimming zeros or anything like that. What should I be looking for here?

 

Thanks for the help.

Matt[/code]

Link to comment
https://forums.phpfreaks.com/topic/188458-leading-zeros-are-being-cutoff/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.