Autor Tema: [OTRA VEZ AYUDA xD] Sistema de comentarios y noticias por pagina.  (Leído 757 veces)

Desconectado Masato

  • PHPero Avanzado
  • ****
  • Mensajes: 480
  • Karma: 12
  • Sexo: Masculino
  • <?php echo "Solo quiero aprender php"; ?>
    • Ver Perfil
    • Masato Design!
[OTRA VEZ AYUDA xD] Sistema de comentarios y noticias por pagina.
« en: 18 de Julio de 2008, 19:52:42 pm »
Hola bueno, vuelvo a pedir ayuda, esta vez quiero que mi web, la que tiene el sistema de noticias, puedan comentar los usuarios que entran, y a la vez, que no hallan mas de 10 o 15 noticias por página, les paso el código del index, y la base de datos, desde ya, MUCHAS GRASIAS!! :D :D

index.php
<?php
include (&#39;funciones.php&#39;);

$config[&#39;host&#39;] = &#39;...&#39;;
$config[&#39;user&#39;] = &#39;...&#39;;    
$config[&#39;pass&#39;] = &#39;...&#39;;
$config[&#39;db&#39;] = &#39;...&#39;;

// here is the start html, <html><body> for example
$start = &#39;<html><head><title>News Flash</title></head><body bgcolor="#ffffff">&#39;;
// here is the end html that is put to document
$end = &#39;</body></html>&#39;;
// news template
$tpl= &#39;<font color ="#FFFBF0" size="1" Font="Verdana"><font face="Verdana">
<!--//%t=Date-->
<!--//%s=Title or Subject-->
<!--//%n=News-->
<!--//%a=User or Posted by-->
<b>%- %s</b><br>
<
br>
%
n
<br>
<
br>
<
b>Por %a</b>
<
br>
<
HR size="1" align="right" width="100%" color="7D889A">
<
br>
</
font> &#39;;
echo $start;

mysql_connect($config[&#39;host&#39;], $config[&#39;user&#39;], $config[&#39;pass&#39;]) or die(&#39;Connection failed&#39;);
mysql_select_db($config[&#39;db&#39;]) or die(&#39;DB selection failed&#39;);

$max mysql_fetch_array(mysql_query(&#39;SELECT MAX(id) FROM wootnews&#39;));
$max $max[&#39;MAX(id)&#39;]+1;

while($result mysql_fetch_array(mysql_query(&#39;SELECT * FROM wootnews WHERE id<&#39; . $max . &#39; ORDER BY id DESC;&#39;)))
   
{
      echo 
str_replace(Array(&#39;%t&#39;, &#39;%a&#39;, &#39;%n&#39;, &#39;%s&#39;), Array($result[&#39;date&#39;], $result[&#39;name&#39;], bbcode($result[&#39;message&#39;]), $result[&#39;subject&#39;]), $tpl);
   
$max $result[&#39;id&#39;];
   
}
   echo 
bbcode ($end); 
?>


admin.php
<?php



$config
[&#39;host&#39;] = &#39;l...&#39;;
$config[&#39;user&#39;] = &#39;...&#39;;    
$config[&#39;pass&#39;] = &#39;...&#39;;
$config[&#39;db&#39;] = &#39;...&#39;;

mysql_connect($config[&#39;host&#39;], $config[&#39;user&#39;], $config[&#39;pass&#39;]) or die(&#39;Connection failed&#39;);
mysql_select_db($config[&#39;db&#39;]) or die(&#39;DB selection failed&#39;);

if(isset($_POST[&#39;news&#39;]))
	
{
	
// name, message, date
	
$message $_POST[&#39;news&#39;];
	
$author $_POST[&#39;author&#39;];
	
$date date(&#39;F j Y&#39;);
        
$subject $_POST[&#39;subject&#39;];
	
mysql_query(&#39;INSERT INTO wootnews (name, message, date, subject, avatar) VALUES ("&#39; . $author . &#39;", "&#39; . $message . &#39;", "&#39; . $date . &#39;",  "&#39; . $subject . &#39;";&#39;) or $error = true;


	
if(isset(
$error))
	
  echo &
#39;There was error in adding news!<br><small>&#39; . mysql_error() . &#39;</small>&#39;;

	
else
	
  echo &
#39;El mensaje ha sido añadido con exito.&#39;;

	
exit;
	
}

echo &
#39;<form action="&#39; . $PHP_SELF . &#39;" method="POST"><font color ="FFFFFF" size="1" Font="Verdana"><font face="Verdana">
News<br><textarea style="border: 1px solid #666666; background: #C0C0C0; font-family: verdana; font-size: 9pt; color:#000000;"
 
rows=10 cols=40 name="news">&#39; . &#39;</textarea>
<br>
Author<br><input style="border: 1px solid #666666; background: #C0C0C0; font-family: verdana; font-size: 9pt; color:#000000;" type="text" name="author">
<
br>
Subject<br><input style="border: 1px solid #666666; background: #C0C0C0; font-family: verdana; font-size: 9pt; color:#000000;" type="text" name="subject"><br><br>
<
input style="border: 1px solid #666666; background: #C0C0C0; font-family: verdana; font-size: 8pt; color:#000000;"
 
type="submit" value="Post">
?>


base_de_datos.sql

CREATE TABLE `wootnews` (
  `
idint(11NOT NULL auto_increment,
  `
nametext NOT NULL,
  `
messagelongtext NOT NULL,
  `
datetext NOT NULL,
  `
subjecttext NOT NULL,
  
PRIMARY KEY  (`id`)
TYPE=MyISAM


Bueno, a partir de eso, como podria empesar??
« Última modificación: 18 de Julio de 2008, 19:54:49 pm por Masato »

Comunidad PHPeros

[OTRA VEZ AYUDA xD] Sistema de comentarios y noticias por pagina.
« en: 18 de Julio de 2008, 19:52:42 pm »

Desconectado G2K

  • Moderador de Programación General
  • PHPero Master
  • ****
  • Mensajes: 2.245
  • Karma: 76
  • Sexo: Masculino
  • Dame un punto de apoyo y moveré la Tierra
    • Ver Perfil
    • Cristian Torrijos
Re: [OTRA VEZ AYUDA xD] Sistema de comentarios y noticias por pagina.
« Respuesta #1 en: 22 de Julio de 2008, 09:31:18 am »
Nose si esta 100% bien porque no puedo probarlo ahora mismo pero seria algo así:

<?php
include (&#39;funciones.php&#39;);

$config[&#39;host&#39;] = &#39;...&#39;;
$config[&#39;user&#39;] = &#39;...&#39;;    
$config[&#39;pass&#39;] = &#39;...&#39;;
$config[&#39;db&#39;] = &#39;...&#39;;

// here is the start html, <html><body> for example
$start = &#39;<html><head><title>News Flash</title></head><body bgcolor="#ffffff">&#39;;
// here is the end html that is put to document
$end = &#39;</body></html>&#39;;
// news template
$tpl= &#39;<font color ="#FFFBF0" size="1" Font="Verdana"><font face="Verdana">
<!--//%t=Date-->
<!--//%s=Title or Subject-->
<!--//%n=News-->
<!--//%a=User or Posted by-->
<b>%- %s</b><br>
<
br>
%
n
<br>
<
br>
<
b>Por %a</b>
<
br>
<
HR size="1" align="right" width="100%" color="7D889A">
<
br>
</
font> &#39;;
echo $start;

mysql_connect($config[&#39;host&#39;], $config[&#39;user&#39;], $config[&#39;pass&#39;]) or die(&#39;Connection failed&#39;);
mysql_select_db($config[&#39;db&#39;]) or die(&#39;DB selection failed&#39;);

$maximo 10//Numero máximo de noticias
while($result mysql_fetch_array(mysql_query("SELECT * FROM wootnews ORDER BY id DESC LIMIT $maximo")))
   {
      echo str_replace(Array(&#39;%t&#39;, &#39;%a&#39;, &#39;%n&#39;, &#39;%s&#39;), Array($result[&#39;date&#39;], $result[&#39;name&#39;], bbcode($result[&#39;message&#39;]), $result[&#39;subject&#39;]), $tpl);
   $max $result[&#39;id&#39;];
   }
   echo bbcode ($end);
?>
Campeón del CatSkills de Webs (Enero 2011)
Campeón del SpainSkills de Webs (Abril 2011)
http://www.youtube.com/watch?v=1fBMG8F_hpM
Mejor representante catalan en SpainSkills 2011