Foros del Web » Programando para Internet » PHP »

Visualizar Comentarios Aprobados

Estas en el tema de Visualizar Comentarios Aprobados en el foro de PHP en Foros del Web. Hola amigos tengo un php que me da de alta mi noticia. alta noticia: Código PHP: <?php      @ session_start ();     require_once( 'auth.php' );     require_once( ...
  #1 (permalink)  
Antiguo 10/08/2009, 17:41
 
Fecha de Ingreso: enero-2009
Mensajes: 246
Antigüedad: 15 años, 3 meses
Puntos: 1
Visualizar Comentarios Aprobados

Hola amigos tengo un php que me da de alta mi noticia.

alta noticia:

Código PHP:
<?php
    
@session_start();
    require_once(
'auth.php');
    require_once(
'config.php');
?>
<!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=iso-8859-1" />
<title>Mi Perfil</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.Estilo1 {color: #0066CC}
.Estilo2 {color: #006699}
.Estilo11 {    color: #006699;
    font-size: 14px;
}
.style1 {color: #000000}
-->
</style>
</head>
<body>
<h1 class="Estilo1"><img src="logo.jpg" alt="UPCN" width="170" height="50" /><span class="Estilo11">Delegaci&oacute;n Nacional del Ministerio de Desarrollo Social de la Naci&oacute;n</span></h1>
<h1 class="Estilo2">Perfil de:  <?php echo $_SESSION['SESS_LAST_NAME'];?></h1>
<p><a href="member-profile.php">Mis Datos</a> | <a href="consultas.php">Consultas</a> | <a href="mensajes.php">Mensajes</a> | <a href="ayudas.php">Ayudas</a> | <a href="novedades-afiliados.php">Novedades Afiliados</a> | <a href="logout.php">Logout</a></p>
<p>&nbsp;</p>
<p align="center">&nbsp;</p>
<br>
<FORM METHOD="POST" ACTION="insert_noticia.php">

<table align="center" border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="54%" id="AutoNumber1" height="119">
  <tr bgcolor="#CCCCCC">
    <td height="19" colspan="6"><span class="Estilo3 style1"><font face="Verdana" size="1">
    INGRESAR UN NUEVO MENSAJE:</font></span></td>
  </tr>
  <tr>
    <td height="19" colspan="6">&nbsp;</td>
  </tr>
  <tr>
    <td width="25%" height="24"><strong><font face="Verdana" size="1">Titulo </font></strong></td>
    <td width="1%" height="24">&nbsp;</td>
    <td width="28%" height="24"><INPUT NAME="titulo" MAXLENGTH="100" TYPE="TEXT" VALUE=""></td>
    <td width="6%" height="24"><strong><font face="Verdana" size="1">Autor:</font></strong></td>
    <td width="1%" height="24">&nbsp;</td>
    <td width="39%" height="24"><?php echo $_SESSION['SESS_LAST_NAME'];?></td>
  </tr>
  <tr>
    <td width="25%" height="19"><strong><font face="Verdana" size="1">Comentario:</font></strong></td>
    <td width="1%" height="19">&nbsp;</td>
    <td height="19" colspan="4">
        <label>
          <textarea name="comentario" cols="70" rows="15"></textarea>
        </label>          </td>
  </tr>
  <tr>
    <td height="19" colspan="6">&nbsp;</td>
  </tr>
  <tr>
    <td height="19" colspan="6"><div align="center">
          <input name="Reset" type="RESET" Value="Limpiar Datos">&nbsp;&nbsp;
          <INPUT NAME="boton" TYPE="SUBMIT" VALUE="Grabar Datos">
    </div></td>
  </tr>
</table>
</form>
</body>
</html>
Tengo mi otro php que recoge los datos y los graba en la db.

Código PHP:
<?php
$con 
mysql_connect("localhost","USUARIO","PASS");
if (!
$con)
  {
  die(
'Could not connect: ' mysql_error());
  }

mysql_select_db("BASE DE DATOS"$con);

$sql="INSERT INTO noticia (titulo,autor,comentario,estado) 
VALUES 
('$_POST[titulo]','$_POST[autor]','$_POST[comentario]','$_POST[estado]')"
;


if (!
mysql_query($sql,$con))
  {
  die(
'Error: ' mysql_error());
  }
//echo "1 record added";

mysql_close($con);
header ("Location: member-index.php");
?>
Ahora por otro lado tengo mi php que aprueba las noticias antes de mostrarlas:

Código PHP:
<script> 
  
function confir(msj,url){ 
  
if(confirm(msj)){ 
window.location = url; 

  
  

  
</script> 
<body>  
  
<form id="form1" name="form1" method="post" action="">  
  <p>  
    <?PHP  
require_once('config.php'); 
$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD); 
$db mysql_select_db(DB_DATABASE);
 
$resultmysql_query("select * from noticia where Aprobado<1") or die('Error: '.mysql_error());    
  
?>  
    <span class="style13">Listado de Noticias <b><u>Por Aprobar</u></b></span></p>  
  <p>&nbsp;  </p>
  <div><center><?php if(!mysql_num_rows($result)) echo "<b>No se encontraron Noticias por Aprobar</b>"?></center></div> 
  <table width="800" border="0" align="center" cellpadding="2" cellspacing="0" >  
  <tr bgcolor="#6699CC">  
    <td><div align="center" class="style14"><span class="style15 style3 style4">ID</span></div></td>  
    <td><div align="center" class="style14"><span class="style15 style3 style4">TITULO</span></div></td>  
    <td><div align="center" class="style14"><span class="style15 style3 style4">NOTICIA</span></div></td>  
    <td><div align="center" class="style14"></div></td>  
    <td><div align="center" class="style14"></div></td>  
    <td><div align="center" class="style14"></div></td>  
    <td><div align="center"><span class="style6"><span class="style14"></span></span></div></td>  
    <td><div align="center"><span class="style6"><span class="style14"></span></span></div></td>  
    <td><div align="center"><span class="style6"><span class="style14"></span></span></div></td>  
  </tr>  
    
    <?php   
      
     
while ($row mysql_fetch_array($result)){  
    echo
"<tr>";  
    echo
"<td><div align='center'><span class='style3'>" .$row['id_comentario']. "</span></div></td>" ;  
    echo
"<td><div align='center'><span class='style3'>" .$row['titulo']. "</span></div></td>" ;  
    echo
"<td><div align='center'><span class='style3'>" .$row['comentario']. "</td>" ;  
    echo
"<td ><div align='center'><span class='style2'> 
   <a href=\"Javascript:confir('Realmente deseas eliminar esta noticia','eliminar_noticia.php?id={$row['id_comentario']}')\">ELIMINAR</a></span></div></td>"
;  
    echo
"<td ><div align='center'><span class='style2'> 
    
    <a href='modifica_noticia.php?id=" 
.$row['id_pf']. "'>VER</a></span></div></td>";  
    echo
"<td ><div align='center'><span class='style2'> 
    <a href=\"Javascript:confir('Realmente deseas Aprobar esta noticia','aprobar_noticia.php?id={$row['id_comentario']}')\">APROBAR</a></span></div></td>"
;  
    echo
" </tr>";  
    }  
    
?>  
</table>   
  
<p class="style5">| <a href="index.php">Inicio</a> |</p>  
</form> 
 
</body> 
</html>
Y por ultimo tengo mi listador de noticias:

Código PHP:
<?php
    
@session_start();
    require_once(
'auth.php');
    require_once(
'config.php');
?>
<!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=iso-8859-1" />
<title>Mi Perfil</title>
<link href="loginmodule.css" rel="stylesheet" type="text/css" />
<style type="text/css">
<!--
.Estilo1 {color: #0066CC}
.Estilo2 {color: #006699}
.Estilo11 {    color: #006699;
    font-size: 14px;
}
.style1 {color: #000000}
-->
</style>
</head>
<body>
<h1 class="Estilo1"><img src="logo.jpg" alt="UPCN" width="170" height="50" /><span class="Estilo11">Delegaci&oacute;n Nacional del Ministerio de Desarrollo Social de la Naci&oacute;n</span></h1>
<h1 class="Estilo2">Perfil de:  <?php echo $_SESSION['SESS_LAST_NAME'];?></h1>
<p><a href="member-profile.php">Mis Datos</a> | <a href="consultas.php">Consultas</a> | <a href="mensajes.php">Mensajes</a> | <a href="ayudas.php">Ayudas</a> | <a href="novedades-afiliados.php">Novedades Afiliados</a> | <a href="logout.php">Logout</a></p>
<p>&nbsp;</p>
<p align="center">&nbsp;</p>
<br>
<FORM METHOD="POST" ACTION="insert_noticia.php">
 <?PHP
require_once('config.php');
$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
$db mysql_select_db(DB_DATABASE);
$resultmysql_query("select * from noticia") or die('Error: '.mysql_error());  

?>
<table width="897" border="0" align="center" cellpadding="2" cellspacing="0">  
  <tr bgcolor="#6699CC">  
    <td bgcolor="#CCCCCC"><div align="center" class="style14">
      <div align="left"><span class="style1">VISUALIZAR NOTICIAS Y COMENTARIOS:</span></div>
    </div></td>
  </tr>  
    
    <?php   
      
     
while ($row mysql_fetch_array($result)){  
    echo
"<tr>";  
    echo
"<td><div align='center'><span class='style3'>" .$row['titulo']. "</span></div></td>" ;  
    echo
"<td><div align='center'><span class='style3'>" .$row['comentario']. "</td>" ;  
    echo
"<td ><div align='center'><span class='style2'> 
   </tr>"
;  
    }  
    
?>  
</table>  
<p>&nbsp;</p>
</form>
</body>
</html>

El problema que estoy teniendo es que me esta listando todas las noticias que dejan grabadas y solo necesito listar aquellas noticias que estan solo aprobadas por el administrador. Alguien podria ayudarme mirando el ultimo codigo a ver en donde estoy fallando.

Saludos y gracias
  #2 (permalink)  
Antiguo 10/08/2009, 17:45
 
Fecha de Ingreso: septiembre-2008
Ubicación: Lanzarote, Canarias
Mensajes: 486
Antigüedad: 15 años, 7 meses
Puntos: 41
Respuesta: Visualizar Comentarios Aprobados

Yo no voy a mirar el código, simplemente por que me parece un lio tremendo, ¡separa el código html de php!.

lo que te puedo decir es que pongas un campo int llamado activo, en el que a las noticias enviadas se les ponga por defecto 0 en ese campo y una vez que tu las aceptes haces un update a 1

En la llamada que muestra los comentarios pones where activo='1' y problema resuelto.
  #3 (permalink)  
Antiguo 10/08/2009, 17:49
Avatar de eft0  
Fecha de Ingreso: junio-2003
Ubicación: Santiago - Chile
Mensajes: 635
Antigüedad: 20 años, 10 meses
Puntos: 9
Respuesta: Visualizar Comentarios Aprobados

En tu último archivo la consulta esta incompleta:

Código PHP:
$resultmysql_query("select * from noticia") or die('Error: '.mysql_error()); 
Debe quedar asi:

Código PHP:
$resultmysql_query("select * from noticia WHERE Aprobado>1") or die('Error: '.mysql_error()); 
Saludos.
__________________
eft0's stuff! - http://estebanfernandez.net
  #4 (permalink)  
Antiguo 10/08/2009, 17:53
 
Fecha de Ingreso: enero-2009
Mensajes: 246
Antigüedad: 15 años, 3 meses
Puntos: 1
Respuesta: Visualizar Comentarios Aprobados

Amigo Eft0 el codigo me quedo asi:

Código PHP:
 <?PHP
require_once('config.php');
$link mysql_connect(DB_HOSTDB_USERDB_PASSWORD);
$db mysql_select_db(DB_DATABASE);
$resultmysql_query("select * from noticia WHERE Aprobado>1") or die('Error: '.mysql_error());   

?>
<table width="897" border="0" align="center" cellpadding="2" cellspacing="0">  
  <tr bgcolor="#6699CC">  
    <td bgcolor="#CCCCCC"><div align="center" class="style14">
      <div align="left"><span class="style1">VISUALIZAR NOTICIAS Y COMENTARIOS:</span></div>
    </div></td>
  </tr>  
    
    <?php   
      
     
while ($row mysql_fetch_array($result)){  
    echo
"<tr>";  
    echo
"<td><div align='center'><span class='style3'>" .$row['titulo']. "</span></div></td>" ;  
    echo
"<td><div align='center'><span class='style3'>" .$row['comentario']. "</td>" ;  
    echo
"<td ><div align='center'><span class='style2'> 
   </tr>"
;  
    }  
    
?>  
</table>  
<p>&nbsp;</p>
</form>
Pero ahora no visualizo ninguna noticia, mire la DB y el estado cambio de 0 a 1 pero no veo ninguna noticia, cual puede ser el problema.

Agradezco la ayuda
  #5 (permalink)  
Antiguo 10/08/2009, 17:59
 
Fecha de Ingreso: enero-2009
Mensajes: 246
Antigüedad: 15 años, 3 meses
Puntos: 1
Respuesta: Visualizar Comentarios Aprobados

ya esta amigo, reemplace el > por el = y salio perfecto

Gracias por toda la mano que me dan
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 04:49.