Foros del Web » Programando para Internet » PHP »

Consulta sql no me funciona

Estas en el tema de Consulta sql no me funciona en el foro de PHP en Foros del Web. hola que tal... Tengo un problemita con la siguiente instruccion: $sql="select * from noticias where id_noticia=' ".$_GET["id_noticia"]." ' "; echo $sql; quiero que se me ...
  #1 (permalink)  
Antiguo 25/10/2010, 13:59
 
Fecha de Ingreso: febrero-2007
Mensajes: 43
Antigüedad: 17 años, 2 meses
Puntos: 0
Información Consulta sql no me funciona

hola que tal...

Tengo un problemita con la siguiente instruccion:

$sql="select * from noticias where id_noticia=' ".$_GET["id_noticia"]." ' ";

echo $sql;


quiero que se me imprima el numero de id_noticia correspondiente a la base de datos... pero me arroja el siguiente error:

Notice: Undefined index: id_noticia in C:\wamp\www\cursophp\vid 9\detalle.php on line 3
select * from noticias where id_noticia=''

.................. se supone que dentro de las comillas me deberia aparecer el numero de id.. que puedo estar haciendo mal?... agradezco la ayuda.
  #2 (permalink)  
Antiguo 25/10/2010, 14:03
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
Tema movido desde Configuración PHP a PHP
  #3 (permalink)  
Antiguo 25/10/2010, 14:05
 
Fecha de Ingreso: julio-2010
Ubicación: La Ciudad Blanca, Mérida-Yucatán
Mensajes: 375
Antigüedad: 13 años, 9 meses
Puntos: 7
Respuesta: Consulta sql no me funciona

el $_GET["id_noticia"] me imagino que lo mandas de un link de otro archivo no es asi?.....postea el codigo del archivo donde esta el link ahi puede estar el error
__________________
--No todos aprendemos de la misma forma, ni a la misma velocidad---
  #4 (permalink)  
Antiguo 25/10/2010, 14:06
 
Fecha de Ingreso: junio-2009
Mensajes: 93
Antigüedad: 14 años, 11 meses
Puntos: 0
Respuesta: Consulta sql no me funciona

Saludos prueba copn esto a ver..

$consulta= "select * from noticias where id_noticia=' ".$_GET["id_noticia"]";
$result= mysql_db_query($base,$consulta) or die (mysql_error());
$array= mysql_fetch_array($result);

echo $array['id_noticia'] //O el campo que quieras imprimir.
  #5 (permalink)  
Antiguo 25/10/2010, 21:24
Avatar de Sourcegeek
Colaborador
 
Fecha de Ingreso: mayo-2009
Ubicación: $mex['B.C.'];
Mensajes: 1.816
Antigüedad: 15 años
Puntos: 322
Respuesta: Consulta sql no me funciona

@JCANARE2; esta mal planteada tu query porque mysql_db_query se ha declarado obsoleta

Intenta esto;
Código PHP:
//Si quieres traer todas las ID
$sqlmysql_query("select * from noticias where id_noticia='".$_GET["id_noticia"]."'");
$row mysql_fetch_assoc($sql);
echo 
$row['id']; 
Lo que hace mysql_query es extraer todos los datos de la tabla que especifiquemos, y con mysql_fetch_assoc se meten todos los datos en un array
echo $row['
__________________
Buscas desarrollador web? Sourcegeek. Diseño web, Maquetación y Programación
¡Escribe bien! Esto es un foro, no un Facebook para que escribas con los pies
  #6 (permalink)  
Antiguo 25/10/2010, 22:08
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Consulta sql no me funciona

Cita:
Iniciado por leoalvis Ver Mensaje
hola que tal...

Tengo un problemita con la siguiente instruccion:

$sql="select * from noticias where id_noticia=' ".$_GET["id_noticia"]." ' ";

echo $sql;


quiero que se me imprima el numero de id_noticia correspondiente a la base de datos... pero me arroja el siguiente error:

Notice: Undefined index: id_noticia in C:\wamp\www\cursophp\vid 9\detalle.php on line 3
select * from noticias where id_noticia=''

.................. se supone que dentro de las comillas me deberia aparecer el numero de id.. que puedo estar haciendo mal?... agradezco la ayuda.
complementando lo que te mencionó zapt142
intenta hacerle echo a $_GET['id_noticia'] antes de la variable $sql para
verificar que este llegando el dato

saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com
  #7 (permalink)  
Antiguo 26/10/2010, 09:03
 
Fecha de Ingreso: febrero-2007
Mensajes: 43
Antigüedad: 17 años, 2 meses
Puntos: 0
Respuesta: Consulta sql no me funciona

buenos dias

este es el codigo del archivo donde esta el link para visualizar el id:

<?php
require_once("conexion.php");
//llamar a los registros de la tabla noticias

$sql="select * from noticias order by id_noticia desc";
$res=mysql_query($sql,$con);
?>

<html>
<head>
</head>
<body>
<table align="center" width="500">
<tr>
<td align="center" valign="top" width="500" colspan="5">
<h3>noticias de mi web</h3>
</td>
</tr>
<tr style="background-color:#666666; color:#ffffff; font-weight:bold">
<td align="center" valign="top" width="150">
Nombre
</td>
<td width="250" align="center" valign="top">
Detalle
</td>
<td width="50" align="center" valign="top">
fecha
</td>
<td width="50" align="center" valign="top">
hora
</td>
<td width="50" align="center" valign="top">

</td>
</tr>

<?php
while ($reg=mysql_fetch_array($res)){

?>
<tr style="background-color:#f0f0f0">
<td align="center" valign="top" width="150">
<?php echo $reg["titulo"]; ?>
</td>
<td width="250" align="center" valign="top">
<?php echo $reg["detalle"]; ?>
</td>
<td width="50" align="center" valign="top">
<?php echo $reg["fecha"]; ?>
</td>
<td width="50" align="center" valign="top">
<?php echo $reg["hora"]; ?>
</td>
<td width="50" align="center" valign="top">
<a href="detalle.php?id_noticia <?php echo $reg["id_noticia"]; ?>" title="Detalle de <?php echo $reg["titulo"]; ?>">
<img src="images/lupa.gif" width="24" height="24" border="0">
</a>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>


intenté con esta instruccion $sql="select * from noticias where id_noticia='".print_r($_GET["id_noticia"])."' ";.... algo positivo es que ya me
aparece este resultado en el navegador...

Notice: Undefined index: id_noticia in C:\wamp\www\cursophp\vid 9\detalle.php on line 3
select * from noticias where id_noticia='1' ... pero me sigue apareciendo el mismo error... agradezco nuevamente la ayudita...
  #8 (permalink)  
Antiguo 26/10/2010, 09:05
Avatar de ylellan  
Fecha de Ingreso: mayo-2010
Ubicación: en un lugar de Veracruz
Mensajes: 432
Antigüedad: 14 años
Puntos: 36
Respuesta: Consulta sql no me funciona

amor que tal si depuras tu consulta, haber que error da:

Código PHP:
$sql="select * from noticias where id_noticia=' ".$_GET["id_noticia"]." ' ";
mysql_query($sql) or die ("error".mysql_error()); 
y haber que da corazon
  #9 (permalink)  
Antiguo 26/10/2010, 09:07
Avatar de mortiprogramador
Colaborador
 
Fecha de Ingreso: septiembre-2009
Ubicación: mortuoria
Mensajes: 3.805
Antigüedad: 14 años, 7 meses
Puntos: 214
Respuesta: Consulta sql no me funciona

Cita:
Iniciado por leoalvis Ver Mensaje
buenos dias

este es el codigo del archivo donde esta el link para visualizar el id:

<?php
require_once("conexion.php");
//llamar a los registros de la tabla noticias

$sql="select * from noticias order by id_noticia desc";
$res=mysql_query($sql,$con);
?>

<html>
<head>
</head>
<body>
<table align="center" width="500">
<tr>
<td align="center" valign="top" width="500" colspan="5">
<h3>noticias de mi web</h3>
</td>
</tr>
<tr style="background-color:#666666; color:#ffffff; font-weight:bold">
<td align="center" valign="top" width="150">
Nombre
</td>
<td width="250" align="center" valign="top">
Detalle
</td>
<td width="50" align="center" valign="top">
fecha
</td>
<td width="50" align="center" valign="top">
hora
</td>
<td width="50" align="center" valign="top">

</td>
</tr>

<?php
while ($reg=mysql_fetch_array($res)){

?>
<tr style="background-color:#f0f0f0">
<td align="center" valign="top" width="150">
<?php echo $reg["titulo"]; ?>
</td>
<td width="250" align="center" valign="top">
<?php echo $reg["detalle"]; ?>
</td>
<td width="50" align="center" valign="top">
<?php echo $reg["fecha"]; ?>
</td>
<td width="50" align="center" valign="top">
<?php echo $reg["hora"]; ?>
</td>
<td width="50" align="center" valign="top">
<a href="detalle.php?id_noticia <?php echo $reg["id_noticia"]; ?>" title="Detalle de <?php echo $reg["titulo"]; ?>">
<img src="images/lupa.gif" width="24" height="24" border="0">
</a>
</td>
</tr>
<?php
}
?>
</table>
</body>
</html>


intenté con esta instruccion $sql="select * from noticias where id_noticia='".print_r($_GET["id_noticia"])."' ";.... algo positivo es que ya me
aparece este resultado en el navegador...

Notice: Undefined index: id_noticia in C:\wamp\www\cursophp\vid 9\detalle.php on line 3
select * from noticias where id_noticia='1' ... pero me sigue apareciendo el mismo error... agradezco nuevamente la ayudita...
ehmmm
y no te falta el = en id_noticia???
idnoticia=<?php echo $reg["id_noticia"]; ?>

por otro lado, envias idnoticia, NO id_noticia, ponle orden a eso
saludos
__________________
"Si consigues ser algo más que un hombre, si te entregas a un ideal, si nadie puede detenerte, te conviertes en algo muy diferente."
Visita piggypon.com

Etiquetas: sql
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:45.