Foros del Web » Programando para Internet » PHP »

Vinculo apuntado hacia entrada especifica de la base de datos

Estas en el tema de Vinculo apuntado hacia entrada especifica de la base de datos en el foro de PHP en Foros del Web. Bueno ahora me tope con este problema y es el ultimo para terminar mi script.. creia que seria facil pero no es asi... En mi ...
  #1 (permalink)  
Antiguo 05/05/2008, 15:01
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Bueno ahora me tope con este problema y es el ultimo para terminar mi script.. creia que seria facil pero no es asi...

En mi script de noticias me muestra 10 encabezados esos 10 tienen link hacia la nota completa de su respectivo encabezado

el problema es que no se como hacer para que al hacer click me manda cierta entrada de la bd por ejemplo...

Estoy viendo el encabezado con el id=16 en mi archivo noti.php y quiero que el vinculo me mande a notas.php en este archivo he especificado que me en liste solo de 1 fila y le puse su barra de navegacion el problema es que quiero que me muestre especificamente una entrada por ejemplo la que tiene el id=16

y lo que hace mal es que me manda al primer id de mi base de datos

espero me comprendan soy malo para plantear preguntas...

intente asi
http://www.elcapitolio.net/noticias/notas.php?id=16
pero no me funciono

Por cierto les agrego que...
Me manda a la primer entrada de mi base de datos y al navegarle (osea darle siguiente, siguiente..) me di cuenta que en mi barra de direcciones cambia a esta url
http://www.elcapitolio.net/noticias/...Rows_ultimas=8
Lo malo que ni el numero 3 ni el 8 es el id de la nota que quiero... esos numero no se de donde los saca...
Pero bueno en fin... que malo que casi no se de PHP.. me desespero mucho, ojala ustedes me tengan paciencia
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México

Última edición por GatorV; 05/05/2008 a las 15:09
  #2 (permalink)  
Antiguo 05/05/2008, 15:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Vinculo apuntado hacia entrada especifica de la base de datos

Hola Capimaster,

En teoría cada que dibujas tu entrada, debes de enviarle el ID que quieras mostrar, pero sin ver tu código es muy complicado encontrar donde esta tu error.

Saludos.
  #3 (permalink)  
Antiguo 05/05/2008, 15:20
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

Mira este es el codigo del archivo que muestra los encabezados:

Código PHP:
<?php require_once('Connections/noticias.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;
}
}

$maxRows_ultimas 10;
$pageNum_ultimas 0;
if (isset(
$_GET['pageNum_ultimas'])) {
  
$pageNum_ultimas $_GET['pageNum_ultimas'];
}
$startRow_ultimas $pageNum_ultimas $maxRows_ultimas;

mysql_select_db($database_noticias$noticias);
$query_ultimas "SELECT * FROM noticias";
$query_limit_ultimas sprintf("%s LIMIT %d, %d"$query_ultimas$startRow_ultimas$maxRows_ultimas);
$ultimas mysql_query($query_limit_ultimas$noticias) or die(mysql_error());
$row_ultimas mysql_fetch_assoc($ultimas);

if (isset(
$_GET['totalRows_ultimas'])) {
  
$totalRows_ultimas $_GET['totalRows_ultimas'];
} else {
  
$all_ultimas mysql_query($query_ultimas);
  
$totalRows_ultimas mysql_num_rows($all_ultimas);
}
$totalPages_ultimas ceil($totalRows_ultimas/$maxRows_ultimas)-1;
?><!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>
<style type="text/css">
<!--
.bordenegro {border:1px solid black;border-bottom:1px solid black}
.notihead {font-family: "Segoe UI", Arial; color: #000000;    font-size: 11px;}
.notititle {font-family: "Segoe UI", Arial; color: #000000;    font-size: 11px; text-align:center; font-weight:bold}
-->
</style>

<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=0,width=640,height=480,left = 365,top = 160');");
}
// End -->
</script>

</head>

<body>
<?php do { ?>
<table width="100%" align="center" cellpadding="0" cellspacing="2"  onmouseover="this.style.background = '#EEEEEE';"  onmouseout="this.style.background = '#FFFFFF';" style=" border-bottom:2px solid #cccccc ">
  <tr>
    <td width="65%"><div class="notititle"><?php echo $row_ultimas['titulo']; ?></div>
        <div align="center"></div></td>
  </tr>
  <tr>
    <td valign="top"><div class="notihead">
    
    <?php echo $row_ultimas['imagen']; ?><img src="<?php echo $row_ultimas['ruta']; ?>" width="130" height="120" hspace="5" vspace="5" align="left" />
     -->
    
    <?php echo $row_ultimas['resumen']; ?></div></td>
  </tr>
  <tr>
    <td valign="top"> <?php echo  "
    
         <div align=right><a href=\"javascript:popUp('http://www.elcapitolio.net/noticias/notas.php?id=$row_ultimas[id]; ')\"><img src=\"/images/vernota2.gif\" width=66 height=15 border=0 /></a></div> 
         "
?>
    
    </td>
  </tr>
</table>
<?php } while ($row_ultimas mysql_fetch_assoc($ultimas)); ?>
<p>&nbsp;</p>



<?php 
echo "

<table width=403 height=127 border=0 cellpadding=2 cellspacing=2>
    <tr>
      <td width=63>&nbsp;</td>
      <td width=51 colspan=2>&nbsp;</td>
    </tr>
    <tr>
      <td height=23 colspan=3><div align=center>$row_ultimas[titulo]</div></td>
    </tr>
    <tr>
      <td height=23 colspan=3>$row_ultimas[contenido]</td>
    </tr>
    <tr>
      <td height=42 colspan=3>
       </td>
    </tr>
    </table>

    "
;
    
?>
</body>
</html>
<?php
mysql_free_result
($ultimas);
?>
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #4 (permalink)  
Antiguo 05/05/2008, 15:21
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

y este otro es el codigo del archivo que muestra cada nota por separado:

Código PHP:
<?php include('Connections/noticias.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;
}
}

$currentPage $_SERVER["PHP_SELF"];

$maxRows_ultimas 1;
$pageNum_ultimas 0;
if (isset(
$_GET['pageNum_ultimas'])) {
  
$pageNum_ultimas $_GET['pageNum_ultimas'];
}
$startRow_ultimas $pageNum_ultimas $maxRows_ultimas;

mysql_select_db($database_noticias$noticias);
$query_ultimas "SELECT * FROM noticias";
$query_limit_ultimas sprintf("%s LIMIT %d, %d"$query_ultimas$startRow_ultimas$maxRows_ultimas);
$ultimas mysql_query($query_limit_ultimas$noticias) or die(mysql_error());
$row_ultimas mysql_fetch_assoc($ultimas);

if (isset(
$_GET['totalRows_ultimas'])) {
  
$totalRows_ultimas $_GET['totalRows_ultimas'];
} else {
  
$all_ultimas mysql_query($query_ultimas);
  
$totalRows_ultimas mysql_num_rows($all_ultimas);
}
$totalPages_ultimas ceil($totalRows_ultimas/$maxRows_ultimas)-1;

$queryString_ultimas "";
if (!empty(
$_SERVER['QUERY_STRING'])) {
  
$params explode("&"$_SERVER['QUERY_STRING']);
  
$newParams = array();
  foreach (
$params as $param) {
    if (
stristr($param"pageNum_ultimas") == false && 
        
stristr($param"totalRows_ultimas") == false) {
      
array_push($newParams$param);
    }
  }
  if (
count($newParams) != 0) {
    
$queryString_ultimas "&" htmlentities(implode("&"$newParams));
  }
}
$queryString_ultimas sprintf("&totalRows_ultimas=%d%s"$totalRows_ultimas$queryString_ultimas);
?><!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>
<style type="text/css">
<!--
body,td,th {
    font-family: Segoe UI, Arial, Times New Roman;
    font-size: 11px;
}
body {
    margin-left: 0px;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 0px;
}
-->
</style></head>

<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td bgcolor="#A50000"><img src="/images/logo.gif" width="380" height="70" /></td>
  </tr>
  <tr>
    <td><iframe src="http://www.elcapitolio.net/uonline52.php" width="100%" height="15" scrolling="No" frameborder="0"></iframe></td>
  </tr>
  <tr>
    <td><table width="96%" height="88" border="0" align="center" cellpadding="0" cellspacing="0">
      <?php do { ?>

      <tr>
        <td height="23"><div align="center">
            <h3><?php echo $row_ultimas['titulo']; ?></h3>
        </div></td>
      </tr>
      <tr>
        <td height="23"><?php echo $row_ultimas['contenido']; ?></td>
      </tr>
      <tr>
        <td height="42"><table border="0" align="center">
            <tr>
              <td><?php if ($pageNum_ultimas 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_ultimas=%d%s"$currentPagemax(0$pageNum_ultimas 1), $queryString_ultimas); ?>"><img src="/images/button_previous.jpg" border="0" /></a>
                  <?php // Show if not first page ?>              </td>
              <td><?php if ($pageNum_ultimas $totalPages_ultimas) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_ultimas=%d%s"$currentPagemin($totalPages_ultimas$pageNum_ultimas 1), $queryString_ultimas); ?>"><img src="/images/button_next.jpg" border="0" /></a>
                  <?php // Show if not last page ?>              </td>
            </tr>
          </table>
            <br />
            <table width="50%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td><form id="form1" name="form1" method="post" action="">
                    <div align="center">
                      <input type="submit" name="Imprimir" id="Imprimir" value="Imprimir" onclick="window.print();return false" />
                      &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                      <input type="submit" name="Imprimir" id="Imprimir" value="Cerrar" onclick="window.close()" />
                    </div>
                </form></td>
              </tr>
          </table></td>
      </tr>
      <?php } while ($row_ultimas mysql_fetch_assoc($ultimas)); ?>
    </table></td>
  </tr>
</table>
</body>
</html>
<?php
mysql_free_result
($ultimas);
?>
<script language=javascript>
function printNews(id){
    window.open("<? echo $path["webroot"?>newsannounce/home.print.php?news_id="+id,"Popup","width=550,height=450,top=70,left=100,dependent=yes,titlebar=no,scrollbars=yes,resizable=yes");    
}

function tellFriend(id,url){
    window.open("<? echo $path["webroot"?>newsannounce/home.tell.php?news_id="+id,"Popup","width=400,height=300,top=170,left=250,dependent=yes,titlebar=no,scrollbars=yes");    
}
</script>
Lamento la combinacion de HTML con PHP pero es que uso el mugroso DW
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #5 (permalink)  
Antiguo 05/05/2008, 16:10
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Vinculo apuntado hacia entrada especifica de la base de datos

El código que genera DW es muy sucio, pero en si te falta rescatar el dato usando $_GET['id'] y en tu consulta hacer algo así:
Código:
SELECT * FROM Noticias WHERE `id`=$id
Saludos.
  #6 (permalink)  
Antiguo 05/05/2008, 17:17
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

hize eso que me dijiste...
y me salio esto :S
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 1' at line 1
bueno en realidad solo hize lo de ...
SELECT * FROM Noticias WHERE `id`=$id

a lo de $_GET['id'] no le entendi mucho
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #7 (permalink)  
Antiguo 05/05/2008, 17:20
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

Si no es mucho pedir... jijiji me puedes ayudar pasandome el codigo ya con la insercion.. y ya yo le cheko que fue lo que moviste para aprender!
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #8 (permalink)  
Antiguo 05/05/2008, 17:27
Avatar de GatorV
$this->role('moderador');
 
Fecha de Ingreso: mayo-2006
Ubicación: /home/ams/
Mensajes: 38.567
Antigüedad: 18 años
Puntos: 2135
Re: Vinculo apuntado hacia entrada especifica de la base de datos

Lo que pasa es que tienes el código de paginar agregado que te hace automáticamente Dreamweaver, tienes que quitar eso y solo cargar el registro especificado.

Saludos.
  #9 (permalink)  
Antiguo 05/05/2008, 18:00
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

Oye ya logre lo que queria muchas gracias... pero me sigue apareciendo esta leyenda...
como me deshago de ella...


You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIMIT 0, 1' at line 1
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #10 (permalink)  
Antiguo 05/05/2008, 18:12
Avatar de Capimaster  
Fecha de Ingreso: agosto-2004
Mensajes: 494
Antigüedad: 19 años, 8 meses
Puntos: 2
Re: Vinculo apuntado hacia entrada especifica de la base de datos

oye sabes que vi lo que me decias y efectivamente el problema era la paginacion...
como lo puedo solucionar?? no sabes?
__________________
http://www.elcapitolio.com.mx - Ocotlán, Jalisco, México
  #11 (permalink)  
Antiguo 06/05/2008, 02:30
Avatar de pateketrueke
Modernizr
 
Fecha de Ingreso: abril-2008
Ubicación: Mexihco-Tenochtitlan
Mensajes: 26.399
Antigüedad: 16 años
Puntos: 2534
Re: Vinculo apuntado hacia entrada especifica de la base de datos

lo ke pasa es un error de sintaxis clarisimo de SQL, obvio... no puedes limitar del 0 al 1, sino... solo 1 y/o mas...

LIMIT 1

sopongo .... :s
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 07:00.