Foros del Web » Programando para Internet » PHP »

Almacenar numero 006002

Estas en el tema de Almacenar numero 006002 en el foro de PHP en Foros del Web. Hola, quisiera saber como puedo almacenar en MySql por medio de php este tipo de numeros: 001, 002 o 006002, etc. NO logro almacenarlo de ...
  #1 (permalink)  
Antiguo 12/07/2010, 07:28
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Almacenar numero 006002

Hola, quisiera saber como puedo almacenar en MySql por medio de php este tipo de numeros: 001, 002 o 006002, etc. NO logro almacenarlo de forma correcta siempre me toma el numero como entero, es decir le doy 001 y me lo transforma en 1. Gracias.
__________________
Mil gracias por sus enseñanzas.

Davincci
  #2 (permalink)  
Antiguo 12/07/2010, 07:32
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Almacenar numero 006002

el campo es Varchar?
__________________
More about me...
~ @rhyudek1
~ Github
  #3 (permalink)  
Antiguo 12/07/2010, 07:48
 
Fecha de Ingreso: julio-2010
Mensajes: 56
Antigüedad: 13 años, 9 meses
Puntos: 3
Respuesta: Almacenar numero 006002

¿No te valdría guardarlos como 1,2,3, etc. y añadirle tu el 00 a la hora de presentar?
  #4 (permalink)  
Antiguo 12/07/2010, 07:49
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Respuesta: Almacenar numero 006002

Pues el campo sea Varchar, no me lo guarda asi. No se que error estoy cometiendo.
__________________
Mil gracias por sus enseñanzas.

Davincci
  #5 (permalink)  
Antiguo 12/07/2010, 08:09
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Respuesta: Almacenar numero 006002

Cita:
Iniciado por Hidek1 Ver Mensaje
el campo es Varchar?
Si es varchar el campo, le agregue 100 de espacio y nada aun sigue el error
__________________
Mil gracias por sus enseñanzas.

Davincci
  #6 (permalink)  
Antiguo 12/07/2010, 08:12
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Almacenar numero 006002

Cita:
Iniciado por davincci Ver Mensaje
Si es varchar el campo, le agregue 100 de espacio y nada aun sigue el error
?.. eso era con los Char.. varchar lee los bit necesarios solamente
podrias pegar tu codigo php aca .. (solamente esa parte).. creo saber en que fallas pero necesito ver

de todas formas podrias intentar usar sprintf para formatear el numero
__________________
More about me...
~ @rhyudek1
~ Github
  #7 (permalink)  
Antiguo 12/07/2010, 08:14
Avatar de davincci  
Fecha de Ingreso: enero-2005
Mensajes: 193
Antigüedad: 19 años, 3 meses
Puntos: 0
Respuesta: Almacenar numero 006002

El codigo php es este:


Código PHP:
<?php require_once('Connections/conex.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  
$theValue function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch (
$theType) {
    case 
"text":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;    
    case 
"long":
    case 
"int":
      
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case 
"double":
      
$theValue = ($theValue != "") ? "'" doubleval($theValue) . "'" "NULL";
      break;
    case 
"date":
      
$theValue = ($theValue != "") ? "'" $theValue "'" "NULL";
      break;
    case 
"defined":
      
$theValue = ($theValue != "") ? $theDefinedValue $theNotDefinedValue;
      break;
  }
  return 
$theValue;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO encuesta (NuevoCodigo) VALUES (%s)",
                       
GetSQLValueString($_POST['NuevoCodigo'], "double"));

  
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());

  
$insertGoTo "Save2.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<form action="<?php echo $editFormAction?>" method="post" name="form1" id="form1">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">NuevoCodigo:</td>
      <td><input type="text" name="NuevoCodigo" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insertar registro" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>
<p>&nbsp;</p>
</body>
</html>
__________________
Mil gracias por sus enseñanzas.

Davincci
  #8 (permalink)  
Antiguo 12/07/2010, 08:22
Colaborador
 
Fecha de Ingreso: octubre-2009
Ubicación: Tokyo - Japan !
Mensajes: 3.867
Antigüedad: 14 años, 6 meses
Puntos: 334
Respuesta: Almacenar numero 006002

wow.. en realidad no me agrada mucho leer codigo generado por dreamweaver
te dejo un ejemplo de sprintf

Código PHP:
Ver original
  1. echo sprintf("%06d", 15); //000015
__________________
More about me...
~ @rhyudek1
~ Github

Etiquetas: almacenar, numero
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 18:31.