Foros del Web » Programando para Internet » PHP »

Mostrar ultimo registro

Estas en el tema de Mostrar ultimo registro en el foro de PHP en Foros del Web. Hola a todos. Como puedo mostrar el ultimo registro de una tabla?. estoy haciendo este trabajo para la U en dreamweaver. En donde necesito mostrar ...
  #1 (permalink)  
Antiguo 26/07/2012, 14:29
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Mostrar ultimo registro

Hola a todos.

Como puedo mostrar el ultimo registro de una tabla?. estoy haciendo este trabajo para la U en dreamweaver. En donde necesito mostrar el ultimo registro es en el campo de texto "numero de guia", gracias de antemano dejo el codigo.

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 guia (FechaEnvio, Remitente, Destinatario, Prioridad, Destinos, TipoEnvio, Transporte, NomRemitente, MovilRemitente, EmailRemitente, NomDestino, MovilDestino, EmailDestino, FechaLlegada, ConfirmaRecepcion, EstadoEnvio, Observacion, Numero) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['FechaEnvio'], "date"),
                       
GetSQLValueString($_POST['Remitente'], "text"),
                       
GetSQLValueString($_POST['Destinatario'], "text"),
                       
GetSQLValueString($_POST['Prioridad'], "text"),
                       
GetSQLValueString($_POST['Destinos'], "text"),
                       
GetSQLValueString($_POST['TipoEnvio'], "text"),
                       
GetSQLValueString($_POST['Transporte'], "text"),
                       
GetSQLValueString($_POST['NomRemitente'], "text"),
                       
GetSQLValueString($_POST['MovilRemitente'], "text"),
                       
GetSQLValueString($_POST['EmailRemitente'], "text"),
                       
GetSQLValueString($_POST['NomDestino'], "text"),
                       
GetSQLValueString($_POST['MovilDestino'], "text"),
                       
GetSQLValueString($_POST['EmailDestino'], "text"),
                       
GetSQLValueString($_POST['FechaLlegada'], "date"),
                       
GetSQLValueString($_POST['ConfirmaRecepcion'], "text"),
                       
GetSQLValueString($_POST['EstadoEnvio'], "text"),
                       
GetSQLValueString($_POST['Observacion'], "text"),
                       
GetSQLValueString($_POST['Numero'], "text"));

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

$maxRows_NumeroConsecutivo 1;
$pageNum_NumeroConsecutivo 0;
if (isset(
$_GET['pageNum_NumeroConsecutivo'])) {
  
$pageNum_NumeroConsecutivo $_GET['pageNum_NumeroConsecutivo'];
}
$startRow_NumeroConsecutivo $pageNum_NumeroConsecutivo $maxRows_NumeroConsecutivo;

mysql_select_db($database_conex$conex);
$query_NumeroConsecutivo "SELECT * FROM consecutivos";
$query_limit_NumeroConsecutivo sprintf("%s LIMIT %d, %d"$query_NumeroConsecutivo$startRow_NumeroConsecutivo$maxRows_NumeroConsecutivo);
$NumeroConsecutivo mysql_query($query_limit_NumeroConsecutivo$conex) or die(mysql_error());
$row_NumeroConsecutivo mysql_fetch_assoc($NumeroConsecutivo);

if (isset(
$_GET['totalRows_NumeroConsecutivo'])) {
  
$totalRows_NumeroConsecutivo $_GET['totalRows_NumeroConsecutivo'];
} else {
  
$all_NumeroConsecutivo mysql_query($query_NumeroConsecutivo);
  
$totalRows_NumeroConsecutivo mysql_num_rows($all_NumeroConsecutivo);
}
$totalPages_NumeroConsecutivo ceil($totalRows_NumeroConsecutivo/$maxRows_NumeroConsecutivo)-1;
?>

<!DOCTYPE html >

<html>

<head>
<title></title>
    <meta  charset="iso-8859-1" />
    <link href="../css/style.css" rel="stylesheet" type="text/css" />
    <!--[if IE 6]>
        <link href="css/ie6.css" rel="stylesheet" type="text/css" />
    <![endif]-->
    <!--[if IE 7]>
        <link href="css/ie7.css" rel="stylesheet" type="text/css" />  
    <![endif]-->
    <link href="../../../css/ie6.css" rel="stylesheet" type="text/css">
    <link href="../../../css/ie7.css" rel="stylesheet" type="text/css">
    <link href="../../../css/style.css" rel="stylesheet" type="text/css">
    <link href="../../css/style.css" rel="stylesheet" type="text/css">
    <style type="text/css">
<!--
.Estilo1 {
    color: #000000;
    font-weight: bold;
}
.Estilo2 {color: #000000}
-->
    </style>
</head>

<body>


<div id="background">
  <div id="page">
              
    <div class="header">
      <div class="footer">
        <div class="body">
          <div id="sidebar"><a href="../index.html"><img id="logo" src="../../../../images/logo.gif" with="154" height="74" alt="" title=""/></a>
<ul class="navigation">
              <li><a  href="../PanelAdministrador.php">Panel Admistrador</a><a  href="../PanelAdministrador.php"></a></li>
                                              <li ></li>
                                </ul>
                                        
                              </div>
<div id="content">
            <div class="content">
              <ul class="article">
                   <li>
                     <h2 align="right">Bienvenido: </h2>
                </li>
                                                    
                   <li>
                     <form method="post" name="form1" action="<?php echo $editFormAction?>">
                       <table align="center">
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Fecha Envío:</span></td>
                           <td><input name="FechaEnvio" type="text" size="32" value="<?php echo date('Y-m-d'); ?>" onFocus="blur()"></td>
                         </tr>
                         
                                                  <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Numero de guía:</span></td>
                           <td><input name="Numero" type="text" onFocus="blur()" value="<?php echo $row_NumeroConsecutivo['Numero']; ?>" size="32"></td>
                         </tr>
                         
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Remitente:</span></td>
                           <td><input type="text" name="Remitente" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Destinatario:</span></td>
                           <td><input type="text" name="Destinatario" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Prioridad:</span></td>
                           <td><input type="text" name="Prioridad" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Destino:</span></td>
                           <td><input type="text" name="Destinos" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Tipo Envio:</span></td>
                           <td><input type="text" name="TipoEnvio" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Transporte:</span></td>
                           <td><input type="text" name="Transporte" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo1">Nombre Remitente:</span></td>
                           <td><input type="text" name="NomRemitente" value="" size="32"></td>
                         </tr>
                         <tr valign="baseline">
                           <td nowrap align="right"><span class="Estilo2"></span></td>
                           <td><input type="submit" value="Insertar registro"></td>
                         </tr>
                       </table>
                       <input type="hidden" name="MM_insert" value="form1">
                     </form>
                     <p>&nbsp;</p>
                   </li>
                <li><strong>Cerrar sesi&oacute;n </strong><strong><img src="../../../../images/Icons/Panel/Clave.png" alt="Cerrar Sesion" width="48" height="48"></strong></li>
                <p>&nbsp;</p>
              </ul>
            </div>
                              </div>
                            </div>
                        </div>
                </div>
                     <div class="shadow">
    </div>
              </div>    
      </div>    
    
</body>
</html>
<?php
mysql_free_result
($NumeroConsecutivo);
?>
  #2 (permalink)  
Antiguo 26/07/2012, 14:31
 
Fecha de Ingreso: enero-2011
Ubicación: DF
Mensajes: 898
Antigüedad: 13 años, 3 meses
Puntos: 155
Respuesta: Mostrar ultimo registro

http://mx2.php.net/manual/es/functio...-insert-id.php
__________________
No me interesan ni las gracias ni los karmas , pero si que se genere conocimiento, si se dio con la respuesta por favor confirmalo
  #3 (permalink)  
Antiguo 26/07/2012, 14:37
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Mostrar ultimo registro

Umm si pero no entiendo, en el caso de mi codigo como hago es aqui donde necesito al menos guardar en una variable el ultimo registro este es el fragmento del codigo donde esta la consulta:

Código PHP:
mysql_select_db($database_conex$conex);
  
$Result1 mysql_query($insertSQL$conex) or die(mysql_error());
}

$maxRows_NumeroConsecutivo 1;
$pageNum_NumeroConsecutivo 0;
if (isset(
$_GET['pageNum_NumeroConsecutivo'])) {
  
$pageNum_NumeroConsecutivo $_GET['pageNum_NumeroConsecutivo'];
}
$startRow_NumeroConsecutivo $pageNum_NumeroConsecutivo $maxRows_NumeroConsecutivo;

mysql_select_db($database_conex$conex);
$query_NumeroConsecutivo "SELECT * FROM consecutivos";
$query_limit_NumeroConsecutivo sprintf("%s LIMIT %d, %d"$query_NumeroConsecutivo$startRow_NumeroConsecutivo$maxRows_NumeroConsecutivo);
$NumeroConsecutivo mysql_query($query_limit_NumeroConsecutivo$conex) or die(mysql_error());
$row_NumeroConsecutivo mysql_fetch_assoc($NumeroConsecutivo);

if (isset(
$_GET['totalRows_NumeroConsecutivo'])) {
  
$totalRows_NumeroConsecutivo $_GET['totalRows_NumeroConsecutivo'];
} else {
  
$all_NumeroConsecutivo mysql_query($query_NumeroConsecutivo);
  
$totalRows_NumeroConsecutivo mysql_num_rows($all_NumeroConsecutivo);
}
$totalPages_NumeroConsecutivo ceil($totalRows_NumeroConsecutivo/$maxRows_NumeroConsecutivo)-1;
?> 
  #4 (permalink)  
Antiguo 26/07/2012, 14:40
 
Fecha de Ingreso: enero-2011
Ubicación: DF
Mensajes: 898
Antigüedad: 13 años, 3 meses
Puntos: 155
Respuesta: Mostrar ultimo registro

a perdon me apentonte tons seria con order by campo desc|asc (segun necesites) limit 1 pa que nomas sea uno

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm
http://dev.mysql.com/doc/refman/5.0/...imization.html
__________________
No me interesan ni las gracias ni los karmas , pero si que se genere conocimiento, si se dio con la respuesta por favor confirmalo
  #5 (permalink)  
Antiguo 26/07/2012, 14:45
 
Fecha de Ingreso: julio-2012
Mensajes: 51
Antigüedad: 11 años, 9 meses
Puntos: 0
Respuesta: Mostrar ultimo registro

$query_NumeroConsecutivo = "SELECT * FROM consecutivos"; aqui iria el limit 1? ando confundido, disculpa la molestia.

Etiquetas: html, mysql, registro, sql, tabla, ultimo
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 23:24.