Ver Mensaje Individual
  #142 (permalink)  
Antiguo 06/05/2010, 06:11
Avatar de Flow89
Flow89
 
Fecha de Ingreso: abril-2010
Ubicación: Valladolid
Mensajes: 346
Antigüedad: 14 años
Puntos: 1
Respuesta: Gestor de Noticias para HTML con PHP [novato]

Me quedo claro Heli0s.

Bueno, ahora tengo otra duda.. que raro no? jajajaja.

El caso es que he creado un panel de administración en el que hay 3 botones.

"Nueva noticia" > Que va a administrar.php
"Editar Noticia" > Que va a editar.php
"Borrar Noticia" > Que va a borrar.php

El caso es que en editar.php, si no le pasas por la URL el id de la noticia, he añadido esto:

Código PHP:
<html>
<head>
<title>Panel de Administracion - Noticias</title>
<script type="text/javascript" src="scripts/widgEditor.js"></script>
<link href="css/widgEditor.css" rel="stylesheet" type="text/css" /> 
<link href="css/widgContent.css" rel="stylesheet" type="text/css" /> 
<link href="css/main.css" rel="stylesheet" type="text/css" /> 
<link href="css/info.css" rel="stylesheet" type="text/css" /> 
<link href="../css/general.css" rel="stylesheet" type="text/css" /> 
<style type="text/css">
<!--
body {
    background-image: url(../imagenes/bg_pattern.gif);
}
-->
</style>
</head>
<body >
<div id="gnoticias">
<?
      
//recibimos la variable id enviada en el enlace por GET
      
$id=$_GET[id];
       include (
"conex.php");
      
//hacemos las consultas
      
$result=mysql_query("select * from noticias where id_noticia='$id'",$connect);
      
//Una vez seleccionados los registros los mostramos para su edición
      
while($row=mysql_fetch_array($result)) {
      echo 
"<div id=\"gnoticias\">
<table width=\"650\" border=\"0\" align=\"center\">
    <tr>
      <td colspan=\"2\"><div align=\"center\"><img src=\"../imagenes/panel.png\" width=\"500\" height=\"200\" /></div></td>
<tr><td>
      <form action=\"edit.php\" method=\"post\">
      <input type=\"hidden\" name=\"id\" value=\""
.$row[id_noticia]."\">
<b>Título:</b><br>
<input type=\"text\" name=\"titulo\" value=\""
.$row[titulo]."\"><br>
<br><b>Autor:</b><br>
<input type=\"text\" name=\"autor\" value=\""
.$row[autor]."\"><br>
      <br><b>Categoría:</b><br>
      <input type=\"text\" name=\"categoria\" value=\""
.$row[categoria]."\"><br>
      <br><b>Escriba el articulo</b><br>
      <textarea name=\"noticia\" class=\"widgEditor\" cols=\"50\" rows=\"10\">\""
.$row[noticia]."\"</textarea>
      <br><input type=\"submit\" value=\"Guardar\" > <input name=\"restablecer\" type=\"reset\" id=\"restablecer\" value=\"Limpiar\" />
      </form>"
;
      echo 
"<form action=\"borrar.php\" method=\"post\">
      <input type=\"hidden\" name=\"id\" value=\""
.$row[id_noticia]."\">
      <input type=\"submit\" value=\"Borrar\"><br>
      </form>
</td></tr>
</table> "

      }
      
mysql_free_result($result);


    
//Realizamos la consulta.
      
$noticias=mysql_query("select * from noticias order by fecha Desc"$connect);
      
$totalnoticias=mysql_num_rows($noticias);
    
//Mostramos las noticias.
      
while ($row=mysql_fetch_array($noticias))
      {echo 
"<span class=\"Estilo35\"><img src=\"imagenes/prueba2.png\" width=\"50\" height=\"50\">" .$row[titulo]."</span><br><p>" .$row[noticia]."</p><br><div> Por: ".$row[autor]." | "
      
.date("d-m-Y",$row[fecha])." | Categoria: ".$row[categoria]." | <a href=\"editar.php?id=".$row[id_noticia]."\">editar</a></div><br><div align=\"center\"><img src=\"imagenes/separador.png\" width=\"400\" height=\"15\"></div>";
      }

      
mysql_close($connect);
      
?>
</div>
</body>
</html>
El caso es que si no le psas la ID te muestra todas las noticias, pero quiero que una vez elija cual es la noticia que quiere editar, muestre SOLO el formulario para editarlo.

No queda más remedio que hacerlo en otra pagina? O se puede hacer de alguna manera en esa misma modificando algo?


Un saludo.