Jump to content


Photo

para aquellos que quieran un sistema de noticias, y a la vez para comentarlas


  • Please log in to reply
1 reply to this topic

#1 kevithoz

kevithoz

    Member

  • Miembros
  • PipPip
  • 29 posts

Posted 28 February 2013 - 11:01 AM

conexion.php

<?php
$con=mysql_connect('localhost','root','123456');
$bd=mysql_select_db('trabajo_de_curso');
?>


ver_noticias.php

<?php
require_once('conexion.php');
$sql="select * from noticias";
$res=mysql_query($sql,$con);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
</style>
<title>Noticias</title>
</head>
<body>
<?php
while($reg=mysql_fetch_array($res))
{
?>
<table align="center" width="290">
<tr align="left" valign="top" height="30">
<td><?php echo $reg['titulo'];?><hr /></td>
</tr>
<tr align="left" valign="top" height="130">
<td><?php echo $reg['detalle'];?><br /><br /><div id="comentar" style=""><a href="detalle.php?id_noticia=<?php echo $reg['id_noticia'];?>">Comentar</a></div><hr /></td>
</tr>
</table>
<?php
}
?>
</body>
</html>


detalle.php

<?php
require_once('conexion.php');
$sql="select * from noticias where id_noticia=".$_GET['id_noticia']." ";
$res=mysql_query($sql,$con);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>
<?php 
$s="select * from noticias where id_noticia=".$_GET['id_noticia']." ";
$r=mysql_query($s,$con);
?>
<?php
if($regi=mysql_fetch_array($r))
{
?>
<?php echo $regi['titulo'];?>
<?php
}
?>
</title>
</head>
<body>
<?php
if($reg=mysql_fetch_array($res))
{
?>
<table align="center" width="528" style="margin-top:50px;">
<tr align="center">
<td align="left"><?php echo $reg['titulo'];?>
</td>
</tr>
<tr align="center">
<td align="justify">
<strong>
<?php echo $reg['detalle'];?>
</strong><hr />
<div id="hora" style="margin-left:px; font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px;">
Este evento se ingreso el <?php echo $reg['fecha'];?>. A las <?php echo $reg['hora'];?>
</div><br />
<a href="ver_noticias.php">Volver a ver las noticias</a>
</td>
</tr>
<table align="justify" width="200" style="margin-left:450px;">
<tr align="center" style="background-color:#CCCCCC">
<td>
<form name="form" action="comentario.php" method="post">
Nombre: <input type="text" name="nombre" />
</td>
</tr>
<tr align="center" valign="top" style="background-color:#ccc">
<td>
Email: <input type="text" style="margin-left:20px;" name="correo" />
</td>
</tr>
<tr align="center" valign="top" style="background-color:#CCCCCC">
<td>
<div id="m" style="margin-left:-158px;">Mensaje:</div><textarea cols="62" rows="10" name="mensaje" style="margin-left: -1px;"></textarea><br />
</td>
</tr>
<input type="hidden" name="id_noticia" value="<?php echo $_GET['id_noticia'];?>" />
<tr style="background-color:#CCCCCC">
<td>
<div id="boton" style="margin-left:139px;">
<input type="submit" value="Comentar" />
</div>
</td>
</tr>
</form>
</tr>
</table>
<table align="center" style="margin-left:450px;">
<tr>
<td>
<?php
$consulta="select * from comentarios where id_noticia=".$_GET['id_noticia']." ";
$result=mysql_query($consulta,$con);
?>
<?php
while($rows=mysql_fetch_array($result))
{
?>
Nombre: <?php echo $rows['nombre'];?><br />
<div align="justify" style="width:520px;"><strong><?php echo $rows['mensaje'];?></strong><hr /></div>
</li>
<?php
}
?>
</td>
</tr>
</ul>
</table>
<?php
}
?>
</body>
</html>


comentario.php

<?php
require_once('conexion.php');
$sql="insert into comentarios values (null,'".$_POST['nombre']."','".$_POST['correo']."','".$_POST['mensaje']."','".$_POST['id_noticia']."')";
$res=mysql_query($sql,$con);

header ('Location: detalle.php?id_noticia='.$_POST['id_noticia']);
?>


bueno, ahora les paso los codigos sql :D


create table noticias
(
id_noticia int not null auto_increment primary key,
titulo varchar (100),
detalle text,
fecha date,
hora time
)


y esta es la tabla de comentarios

create table comentarios
(
id_comentario int not null auto_increment primary key,
nombre varchar (100),
correo varchar (100),
mensaje text,
id_noticia int
)


Antes de crear las consultas sql, deben crear una base de datos llamada "trabajo_de_curso"

Bueno amigos, esto es para aquellos que tienen errores en el video de cesar cancino, por su puesto este contenido no es mio, es de cesar, y ya que tube muchos errores y los fui aprendiendo, quiero que ustedes hagan lo mismo, Gracias :D
  • 0

#2 poliburro

poliburro

    Advanced Member

  • Administrador
  • 4945 posts
  • LocationMéxico

Posted 28 February 2013 - 11:31 AM

Gracias por compartirnos amigo¡¡¡¡¡¡¡¡ :D
  • 0




IP.Board spam blocked by CleanTalk.