olá amigos
minha pergunta acho q é simples, talvez até boba...
tenho uma tabela onde precisaria inserir no bd o numero 001 ao inves de 1
hj eu insiro automaticamente ...
desta maneira:
$sqlSeq = mysql_query ("SELECT MAX(seq) AS MaiorSeq FROM suprisul_orcamento_dados ");
$linhaSeq = mysql_fetch_array($sqlSeq);
$seq2 = $linhaSeq["MaiorSeq"];
$seq = $seq2 + 1;
mas precisava q fosse 001
como posso fazer? q tipo de campo pode ser:
brigadinho
3 Digitos
Started By guerreira, 14/02/2005, 08:37
1 reply to this topic
#1
Posted 14/02/2005, 08:37
#2
Posted 14/02/2005, 09:01
eu nunca vi uma função para isso e não achei no php, então eu fiz uma:
Use-a assim:
int_fill(1, 3);
e ela retorna: 001
Eu estou sem disponibilidade para testar o script no momento, portanto pode ser que não funcione.
fuction int_fill($theint, $fillvalue) { // Verifica se o número precisa de zeros if (strlen($theint) >= strlen($fillvalue)) { // Retorna o número sem modificações return $theint; } else { // Retorna o número com zeros return intval(str_repeat("0", (strlen($theint) - strlen($fillvalue)).$theint); } }
Use-a assim:
int_fill(1, 3);
e ela retorna: 001
Eu estou sem disponibilidade para testar o script no momento, portanto pode ser que não funcione.
Alexandre Gomes Gaigalas
http://alexandre.gaigalas.net
http://alexandre.gaigalas.net
0 user(s) are reading this topic
0 membro(s), 0 visitante(s) e 0 membros anônimo(s)