Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » Mysql »

Saber el ultimo autoincrement relacionado

Estas en el tema de Saber el ultimo autoincrement relacionado en el foro de Mysql en Foros del Web. Hola gente tengo la siguiente estructura Código PHP:       CREATE TABLE   ` notas ` (         ` notasID `  int ( 10 )  UNSIGNED NOT NULL AUTO_INCREMENT ,         ` userID `  int ...
  #1 (permalink)  
Antiguo 29/01/2009, 22:42
 
Fecha de Ingreso: junio-2008
Mensajes: 119
Antigüedad: 15 años, 10 meses
Puntos: 1
Saber el ultimo autoincrement relacionado

Hola gente tengo la siguiente estructura

Código PHP:
      CREATE TABLE  `notas` (
        `
notasIDint(10UNSIGNED NOT NULL AUTO_INCREMENT,
        `
userIDint(10UNSIGNED NOT NULL,
        `
posterTimeint(10UNSIGNED NOT NULL,
        `
posterIPtinytext NOT NULL,
        `
titulotinytext NOT NULL,
        `
cuerpotext NOT NULL,
        `
tagsvarchar(16) DEFAULT NULL,
        `
categoriavarchar(16NOT NULL,
        `
visitasIDmediumint(8unsigned NOT NULL auto_increment,
        `
visitasIPtinytext NOT NULL,
        
PRIMARY KEY  (`notasID`),
        
KEY `FK_notas_1` (`userID`),
        
FOREIGN KEY (`userID`) REFERENCES `usuarios` (`userID`)
      ) 
ENGINE=InnoDB DEFAULT CHARSET=latin1
y realizo esta insercion

Código PHP:
$sql="INSERT INTO notas (notasID ,userID,posterTime,posterIP,titulo,cuerpo,tags,categoria)VALUES (NULL , '$userID', '$time', '$ip', '$titulo', '$cuerpo', '$tags', '$categoria')"
La pregunta es saber cual es el valor de notasID, asi q despues del momento de crearla la pueda enlazar....

Muchas gracias espero que me entiendan...
  #2 (permalink)  
Antiguo 30/01/2009, 04:54
Avatar de jerkan  
Fecha de Ingreso: septiembre-2005
Mensajes: 1.607
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: Saber el ultimo autoincrement relacionado

Si notasID tiene AUTO_INCREMENET, no tienes que asignarle un valor al hacer el INSERT ya que éste se asigna automáticamente.

Para obtener el valor asignado utiliza la funcion LAST_INSERT_ID.

Un saludo
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 11:12.