Ver Mensaje Individual
  #1 (permalink)  
Antiguo 11/12/2003, 19:17
javier55
 
Fecha de Ingreso: septiembre-2003
Ubicación: Barcelona
Mensajes: 41
Antigüedad: 20 años, 8 meses
Puntos: 0
urgente, please, mostrar ultimo id de una tabla

hola,

Como siempre agradeceros toda vuestra ayuda

tengo que mostrar el ultimo id de una tabla para asignarlo a otro registro, lo hice con select max(registro) where ... y lo mostré con un bucle while y for each, mi problema es que funcionando en localhost rula ok, pero cuando lo subo al servidor no me muestra el dato, os dejo el código y a ver si alguien me puede decir como solucionarlo a hacerlo de otro modo más sencillo con el que no tenga problemas con diferentes versiones del motor base de datos.

os pongo el código

<?


$conexion = mysql_connect("localhost", "j", "jr");
$basededatos = mysql_select_db("almacen", $conexion);

if ( (!$conexion) || (!$basededatos) ) {

if (!$conexion) {

echo ("<h2 align=\"center\">ERROR: Imposible establecer conexi&oacute;n con el servidor</h2>");

} else if (!$basededatos) {

echo ("<h2 align=\"center\">ERROR: Imposible establecer conexi&oacute;n con la base de datos</h2>");
}

exit;
}

$ref = $_POST['descripcion3'];

$query = "SELECT referencia, descripcion, familia, subfamilia FROM articulos WHERE (descripcion = '$ref')";
$result = mysql_query($query, $conexion);
$row = (mysql_fetch_array($result));


$reference = $row['referencia'];
$fam = $row['familia'];
$subfam = $row['subfamilia'];

$registry = "SELECT MAX(id) from reservas" ;
$registry1 = (mysql_query($registry, $conexion));




?>




<HTML>
<HEAD>
<TITLE>Formu2 - PHP</TITLE>
<meta http-equiv="" content="text/html; charset=iso-8859-1">

</HEAD>

<BODY>
<form method='post' name="form1" action="altareserva4.php">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Identificador:</td>
<td colspan="2"><input name="identificador" type="text" value="<? while ($identificador = (mysql_fetch_row($registry1))) { foreach($identificador as $clave){ echo $clave ; }}
?>"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Referencia:</td>
<td colspan="2"><input name="referencia" type="text" value="<? echo $reference ?>"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Descripcion:</td>
<td colspan="2"><input name="descripcion" type="text" value="<? echo $ref ?>" size="80" maxlength="80"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Familia:</td>
<td colspan="2"><input name="familia" type="text" value="<? echo $fam ?>" size="3" maxlength="3"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Subfamilia:</td>
<td colspan="2"><input name="subfamilia" type="text" value="<? echo $subfam ?>" size="3" maxlength="3"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Cantidad:</td>
<td colspan="2"><input name="cantidad" type="int" value= "0" size="6" maxlength="6"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Emplazamiento:</td>
<td colspan="2"><input name="emplazamiento" type="text" value="" size="40" maxlength="40"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Solicitado por:</td>
<td colspan="2"><input name="solicitado_por" type="text" value="" size="30" maxlength="30"></td>
</tr>

<tr valign="baseline">
<td nowrap align="right">Fecha:</td>
<td colspan="2"><input name="fecha" type="text" value="01-01-2003" size="10" maxlength="10"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Observaciones:</td>
<td colspan="2"><input name="observaciones" type="text" value="" size="80" maxlength="80"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><div align="center">
<input type="submit" value="Insertar registro">
</div></td>
<td><div align="center"><INPUT TYPE=BUTTON NAME="miBoton" VALUE="Cerrar ventana" onClick="self.close()"> </div></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td colspan="2">&nbsp;</td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><div align="center"> </div></td>
<td><div align="center"> </div></td>
</tr>
</table>

</form>
<? require("altareserva.php"); ?>
</BODY>
</HTML>

muchas gracias