este es el codigo
Código PHP:
<?
$mostrar = 5;
$host = "localhost";
$user = "root";
$pass = "";
$dbname = "pruebas";
$conecta = mysql_connect($host,$user,$pass);
mysql_select_db($dbname,$conecta)or die("Error en conexion");
if ($n) {
$query = "select * from news where id='$n'";
$resp = mysql_query($query) ;
while ($datos = mysql_fetch_array($resp)) {
$fecha = date("d/m/Y",$datos[fecha]);
$titulo = strtoupper($datos[titulo]);
$noticia = nl2br($datos[noticia]);
$caracteres = strlen($datos[noticia]);
$preview = nl2br($datos[preview]);
echo "
<table width=\"524\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#3A5695\" height=\"8\">
<tr>
<td width=\"398\" height=\"2\" bgcolor=\"#336699\" bordercolor=\"#333333\">
<div align=\"center\"><font face=\"Verdana\" color=\"#FFFFFF\"><font size=\"2\"><font size=\"2\">$titulo</font></font></font></div>
</td>
<td height=\"2\" width=\"120\" bgcolor=\"#336699\" bordercolor=\"#333333\">
<div align=\"center\"><font face=\"Verdana\" color=\"#FFFFFF\"><font size=\"2\"><font size=\"2\">$fecha</font></font></font></div>
</td>
</tr>
<tr>
<td colspan=\"2\" height=\"2\" bordercolor=\"#3A5695\">
<div align=\"left\"><font face=\"Verdana\" size=\"2\" color=\"#000000\">$preview
</font><font face=\"Verdana\" size=\"2\" color=\"#FFFFFF\"><br>
<hr align=\"center\" width=\"50%\">
<font color=\"#000000\">$noticia</font></font></div>
</td>
</tr>
</table>
<br>
<a href=\"javascript:history.back()\">Volver</a>
</div>
\n";
}
}else{
$query = "select * from news order by id desc";
$resp = mysql_query($query) or die("Error en consulta");
while ($datos = mysql_fetch_array($resp)) {
if ($mostrar > 0) {
$fecha = date("d/m/Y",$datos[fecha]);
$titulo = strtoupper($datos[titulo]);
$noticia = nl2br($datos[noticia]);
$caracteres = strlen($datos[noticia]);
$preview = nl2br($datos[preview]);
echo "
<table width=\"524\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#3A5695\" height=\"8\">
<tr>
<td width=\"398\" height=\"2\" bgcolor=\"#336699\" bordercolor=\"#333333\">
<div align=\"center\"><font face=\"Verdana\" color=\"#FFFFFF\"><font size=\"2\"><font size=\"2\">$titulo</font></font></font></div>
</td>
<td height=\"2\" width=\"120\" bgcolor=\"#336699\" bordercolor=\"#333333\">
<div align=\"center\"><font face=\"Verdana\" color=\"#FFFFFF\"><font size=\"2\"><font size=\"2\">$fecha</font></font></font></div>
</td>
</tr>
<tr bgcolor=\"#000000\">
<td height=\"2\" colspan=\"2\" bordercolor=\"#3A5695\"> <div align=\"left\"><font face=\"Verdana\" size=\"2\" color=\"#FFFFFF\">$preview</font></div></td>
</tr>
</table>
<table width=\"524\" height=\"8\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bordercolor=\"#3A5695\">
<tr bgcolor=\"#000000\">
<td height=\"2\" colspan=\"2\" valign=\"top\" bordercolor=\"#999999\" bgcolor=\"#FFFFFF\"> <div align=\"right\"><font face=\"Verdana\" size=\"2\" color=\"#000000\">$caracteres
carateres [<a href=\"mostrar.php?n=$datos[id]\">Ver mas</a>] </font></div></td>
</tr>
</table>
\n";
$mostrar--;
}
}
}
mysql_query($query);
mysql_close($conecta);
?>