Foros del Web » Programando para Internet » PHP »

Problemas con sistema de noticias

Estas en el tema de Problemas con sistema de noticias en el foro de PHP en Foros del Web. Saludos, desarrollando un sistema de noticias quise hacer la paginacion y que desde un panel pudiese eliminar o modificar las mismas y no he podido... ...
  #1 (permalink)  
Antiguo 12/09/2007, 11:31
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Problemas con sistema de noticias

Saludos,
desarrollando un sistema de noticias quise hacer la paginacion y que desde un panel pudiese eliminar o modificar las mismas y no he podido... y no se muestran todos los registros.. solo el primero.. alguien podria decirme como hacer q salgan todos los registros???... y como hacer la paginacion?

Código:
<?php virtual('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;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
  $insertSQL = sprintf("INSERT INTO noticias (id, fecha, noticia) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['fecha'], "date"),
                       GetSQLValueString($_POST['noticia'], "text"));

  mysql_select_db($database_noticias, $noticias);
  $Result1 = mysql_query($insertSQL, $noticias) or die(mysql_error());

  $insertGoTo = "registro.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_noticias, $noticias);
$query_Recordset1 = "SELECT * FROM noticias";
$Recordset1 = mysql_query($query_Recordset1, $noticias) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
</form>

<form action="<?php echo $editFormAction; ?>" method="post" name="form2" id="form2">
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Fecha:</td>
      <td><input type="text" name="fecha" value="<?php echo $row_Recordset1['fecha']; ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right" valign="top">Noticia:</td>
      <td><textarea name="noticia" cols="50" rows="5"><?php echo $row_Recordset1['noticia']; ?></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">&nbsp;</td>
      <td><input type="submit" value="Insert record" /></td>
    </tr>
  </table>
  <input type="hidden" name="id" value="" />
  <input type="hidden" name="MM_insert" value="form2" />
</form>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="10%">ID</td>
    <td width="14%">Fecha</td>
    <td width="60%">Noticia</td>
    <td width="16%">&nbsp;</td>
  </tr>
  <tr>
    <td><?php echo $row_Recordset1['id']; ?></td>
    <td><?php echo $row_Recordset1['fecha']; ?>;</td>
    <td><?php echo $row_Recordset1['noticia']; ?></td>
    <td>Eliminar / Modificar</td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>

Última edición por T4ke0veR; 12/09/2007 a las 11:37
  #2 (permalink)  
Antiguo 12/09/2007, 11:40
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Re: Problemas con sistema de noticias

Para la paginacion analiza este post

http://www.forosdelweb.com/f18/presentar-5-5-a-517906/

Saludos
  #3 (permalink)  
Antiguo 12/09/2007, 11:49
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

ok pero fijate algo... cuando inserto los registros se guardan en la base de datos mas no aparecen en la pagina como deberian... a q se debe esto?? donde tendre el error???...
  #4 (permalink)  
Antiguo 12/09/2007, 11:54
Avatar de Carlojas  
Fecha de Ingreso: junio-2007
Ubicación: Shikasta
Mensajes: 1.272
Antigüedad: 16 años, 10 meses
Puntos: 49
Re: Problemas con sistema de noticias

tienes estas lineas

Código PHP:
    <td><?php echo $row_Recordset1['id']; ?></td>
    <td><?php echo $row_Recordset1['fecha']; ?>;</td> Tienes un ; de mas
    <td><?php echo $row_Recordset1['noticia']; ?></td>
Cambialas por estas


Código PHP:
<td><?php echo "$row_Recordset1[id]"?></td>
    <td><?php echo "$row_Recordset1[fecha]"?></td>
    <td><?php echo "$row_Recordset1[noticia]"?></td>

Saludos
  #5 (permalink)  
Antiguo 12/09/2007, 12:02
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

el codigo que pones es una funcion que inserte dreamweaber cuando namas lo tocas , para hacer una paginacion con dreamweaver despues de hacer tu juego de registros, vas al menu insertar + objetos de aplicacion + paginado de juego e registros + barra de navegacion de juego de registros, tambien lo puedes hacer desde el panel comportamientos del servidor (perdon si la descripcion del menu no es asi, es que yo tengo el dreamweaver en ingles).

tambien puedes ver este ejemplo muy bueno (http://jpinedo.webcindario.com/scrip...tor/index.html), espero te sea util

AH! y para que te muestre mas de un registro de la tabla en tu base de datos, tienes que hacer una region repetida (do... while), igual desde el menu insertar o desde el panel comportamiento del servidor

saludos y suerte
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #6 (permalink)  
Antiguo 12/09/2007, 12:13
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

me dio esto
Notice: Undefined variable: row_Recordset1 in c:\archivos de programa\easyphp1-8\www\basinger\news.php on line 0
  #7 (permalink)  
Antiguo 12/09/2007, 12:31
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

por que no nos muestras el codigo del recordset?
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #8 (permalink)  
Antiguo 12/09/2007, 12:32
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

quiero es q me salgan 3 noticias por pagina pero de verdad no se como se hace eso
  #9 (permalink)  
Antiguo 12/09/2007, 12:40
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

a ver, te sale una al menos? codigoooo codigooooo, a ver el codigooooooooOo
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #10 (permalink)  
Antiguo 12/09/2007, 12:42
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

Código PHP:
<?php
mb_http_input
("utf-8");
mb_http_output("utf-8");
?>
<?php virtual
('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;
}
}

$editFormAction $_SERVER['PHP_SELF'];
if (isset(
$_SERVER['QUERY_STRING'])) {
  
$editFormAction .= "?" htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset(
$_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO noticias (id, fecha, noticia) VALUES (%s, %s, %s)",
                       
GetSQLValueString($_POST['id'], "int"),
                       
GetSQLValueString($_POST['fecha'], "date"),
                       
GetSQLValueString($_POST['noticia'], "text"));

  
mysql_select_db($database_noticias$noticias);
  
$Result1 mysql_query($insertSQL$noticias) or die(mysql_error());

  
$insertGoTo "registro.php";
  if (isset(
$_SERVER['QUERY_STRING'])) {
    
$insertGoTo .= (strpos($insertGoTo'?')) ? "&" "?";
    
$insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  
header(sprintf("Location: %s"$insertGoTo));
}

mysql_select_db($database_noticias$noticias);
$query_Recordset1 "SELECT * FROM noticias";
$Recordset1 mysql_query($query_Recordset1$noticias) or die(mysql_error());
$row_Recordset1 mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 mysql_num_rows($Recordset1);
?><!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>Untitled Document</title>
</head>

<body>
<p>Noticias</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="14%"><?php echo "$row_Recordset1[fecha]"?></td>
  </tr>
  <tr>
<td><?php echo "$row_Recordset1[noticia]"?></td>
  </tr>
</table>
<p>&nbsp;</p>
</body>
</html>
<?php
mysql_free_result
($Recordset1);
?>
  #11 (permalink)  
Antiguo 12/09/2007, 12:46
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

ok me sale 1, pero ahora... debo hacer una pagina donde me muestre las ultimas 3 publicadas y la otra donde me muestre de 10 en 10 todas q es la q lleva el boton eliminar o modificar por cada una de las noticias!
  #12 (permalink)  
Antiguo 12/09/2007, 13:00
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

a ver, desde el principio, ya esta la noticia, ahora en el recor set donde dice:
Código PHP:
$query_Recordset1 "SELECT * FROM noticias"
le pones:
Código PHP:
$query_Recordset1 "SELECT * FROM noticias ORDER BY idnoticia DESC LIMIT 3"
idnoticia es el campo id de tu tabla, acomodas el nombre a lo tuyo
ahora, para que te muestre mas de una tienes que hacer una region repetida, como te indique mas arriba, de todas maneras te quedara mas o menos asi:
Código PHP:
<?php do { ?>
<table width="100%" border="0" cellspacing="0" cellpadding="0"> 
  <tr> 
    <td width="14%"><?php echo $row_Recordset1['fecha']; ?></td> 
  </tr> 
  <tr> 
<td><?php echo $row_Recordset1['noticia']; ?></td> 
  </tr> 
</table> 
<?php } while ($row_Recordset1 mysql_fetch_assoc($Recordset1)); ?>
PD: con el LIMIT 3 en tu consulta, te mostrara solo 3 registros, claro el #to es cambiable por la cantidad de registros que quieras mostrar.

saludos y vamos por parte

EDITO: acostumbrate a ponerle nombres a tus recorsets, para que no te pierdas (consegito sano que sale barato)
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #13 (permalink)  
Antiguo 12/09/2007, 13:14
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

gracias brother... bueno ahora tngo q ver como hago para q salgan varios.. me esta mostrando el ultimo resultado q publico... ahora tngo q hacer la region repetida... vamos a ver como!!!!
  #14 (permalink)  
Antiguo 12/09/2007, 13:30
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

no te salio con el LIMIT? ok, cuando haces la region repetida con dreamweaver, el te progunta si quieres mostrar todos o una cantidad especifica de registros, ve a ver eso que te digo, asi te mostrara la cantidad qeu quieres, ya despues lo del paginado

saludos y abanti, siempre abanti

EDITO: para hacer la region repetida, seleccionas la tabla, ok
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #15 (permalink)  
Antiguo 12/09/2007, 14:32
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

aaaaaaaaaah tngo el DW en ingles y no consigo la funcion para hacer el duplicado...!!!!
  #16 (permalink)  
Antiguo 12/09/2007, 14:43
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

insert + aplication objects + repeated region
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #17 (permalink)  
Antiguo 12/09/2007, 14:51
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias





nooooooooooooooooooooooooo...
gracias ya funciono... no los molesto por un time.. gracias a todos y muchas gracias rogertm.. muy buena tu ayuda!!!!
saludos
  #18 (permalink)  
Antiguo 12/09/2007, 14:55
Avatar de rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 8 meses
Puntos: 638
Re: Problemas con sistema de noticias

un placer ayudar, por que a mi me han ayudado mucho tambien, jejejeje, dale las gracias a FDW
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose
  #19 (permalink)  
Antiguo 12/09/2007, 15:01
Avatar de T4ke0veR  
Fecha de Ingreso: agosto-2007
Ubicación: Quito - Ecuador
Mensajes: 1.720
Antigüedad: 16 años, 8 meses
Puntos: 28
Re: Problemas con sistema de noticias

jejeje ok... a penas culmine la pagina se las muestro para q vean como quedo!!!!
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 15:01.