Ver Mensaje Individual
  #8 (permalink)  
Antiguo 04/02/2012, 17:46
kenyis01
 
Fecha de Ingreso: mayo-2010
Mensajes: 53
Antigüedad: 14 años
Puntos: 0
Respuesta: Limitar caracteres de una consulta

Perfecto, ahí me salio, lo dejo por si alguno tiene el mismo problema:

Código PHP:
Ver original
  1. <?php
  2.            include ("include/config.php");
  3.            $db = mysql_connect($dbhost,$dbusername,$dbpass);
  4.            mysql_select_db($dbname) or die($dberror);
  5.            @mysql_query("SET NAMES 'utf8'"); // para el error molesto de los acentos y las ñ
  6.            $query = "SELECT * FROM noticias WHERE publicada = 1 ORDER BY id DESC LIMIT 1;";
  7.            $result = mysql_query($query);
  8.            echo "<div id='ultimas_noticias_tabla'><table cellSpacing='0' cellPadding='0' width='260' height='50' border='0'>";
  9.            while ($r = mysql_fetch_array($result)) {
  10.            $limitar = substr($r['contenido'],0,215); // limitar los caracteres de la consulta
  11.            echo "<tr><td class='titulo_ultimas_noticias'><strong>" . $r['titulo'] . "</strong></td></tr>";
  12.            echo "<tr><td class='fecha_ultimas_noticias'>" . $r['fecha'] . "</td>";
  13.            echo "<tr><td class='contenido_ultimas_noticias' width=>" . $limitar . "... <a href='noticias.php' alt='mas'>[+]</a></td></tr>";
  14.            }
  15.            ?>