Hola comunidad, al pulsar en las categorias, si no tengo post en esa categoria quiero que vaya a una pagina y me salga un mensaje advirtiendo: "No hay post en esta categoria" o algo asi, como lo puedo hacer??

Gracias ysalu2
Editado
0
Puntos
967
Visitas
15
Resp
Por borch hace 12 años
Developer
Respuesta #1
pon tu código de la pagina categorias.php
0
Puntos
Por zeuskx hace 12 años
Mods
Respuesta #2
<?php require_once('../Connections/conexionforo.php'); 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

$colname_Categoriafiltro = "-1";
if (isset($_GET['buscar'])) {
  $colname_Categoriafiltro = $_GET['buscar'];
}
mysql_select_db($database_conexionforo, $conexionforo);
$query_Categoriafiltro = sprintf("SELECT * FROM posts WHERE categoria LIKE %s", GetSQLValueString("%" . $colname_Categoriafiltro . "%", "text"));
$Categoriafiltro = mysql_query($query_Categoriafiltro, $conexionforo) or die(mysql_error());
$row_Categoriafiltro = mysql_fetch_assoc($Categoriafiltro);
$totalRows_Categoriafiltro = mysql_num_rows($Categoriafiltro);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo $row_Datosweb['titulo']; ?></title>
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $row_Datosweb['url']; ?>skins/default/img/favicon.ico">
<meta name="description" content="<?php echo $row_Datosweb['descripcion']; ?>">
<meta name="keywords" content="<?php echo $row_Datosweb['keywords']; ?>
">

<link href="../skins/default/css/estilos.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="contenedor">
  <div id="head">
   <div id="cabecera">
    <div id="logo"><a href="<?php echo $row_Datosweb['url']; ?>"><img src="../skins/default/img/logo.png" width="200" height="50" alt="logo"></a></div>
    <div id="buscador">
      <?php include("../includes/buscador.php"); ?>
    </div>
   </div>
  </div>
  <div id="menu">
    <?php include("../includes/menu.php"); ?>
    <?php include("../includes/usuarios.php"); ?>
  </div>
  <div id="cuerpo"><table width="100%" height="100%" border="0">
  <tr>
    <td width="100%" valign="top"><div id="izquierda">
      <table width="100%" border="0" class="resultados">
        <tr>
          <td width="69%" class="tituloresultado"><a href="../<?php echo $row_Categoriafiltro['seo']; ?>.html"><?php echo $row_Categoriafiltro['titulo']; ?></a></td>
          <td width="31%" align="right"><span style="font-size:11px"><?php echo $row_Categoriafiltro['fecha']; ?></span></td>
        </tr>
        <tr>
          <td colspan="2">
          <?php // codigo para recortar los caracteres
		  $contenidocorto=($row_Categoriafiltro['mensajes']);
		  if ((strlen($contenidocorto))> 300) {	
		  $contenidocorto=substr($contenidocorto, 0, 85); 
		  }
		  echo $contenidocorto;include("../includes/leermas.php"); 
		  ?>
          </td>
          </tr>
      </table>
    </div></td>
    <td width="310" valign="top"><div id="derecha">
      <div id="bloques"><?php echo $row_Sacarextras['anuncio']; ?></div>
      <div id="bloques">
        <?php include("../includes/bloque_categorias.php"); ?>
        <?php include("../includes/bloque_comentarios.php"); ?>
    </div></td>
  </tr>
</table>
</div>
  <div id="footer">
  <?php include("../includes/footer.php"); ?>
</div>
</body>
</html>
<?php
mysql_free_result($Categoriafiltro);
?>
y tambien en la linea donde he puesto el leer mas, este no me funciona, la ruta que me da es "page/.html" ahunque la ruta que le he dado es absoluta
0
Puntos
Por borch hace 12 años
Developer
Respuesta #3
<?php if ($totalRows_DatosPost > 0) { // Show if recordset not empty ?> ///aqui muestra los datos su hay
<?php do { ?>
<div id="listado">
<div id="listas_h">
<div id="lista_left">
<div id="lista_ti">
<div id="listado_caja"><img src="skins/defaul/img/open.png" width="26" height="26" alt="abierto" /></div>
<a href="verpost.php?recordID=<?php echo $row_DatosPost['idPost']; ?>"> <?php
echo $row_DatosPost['strTitulo'];
?>
</a>
</div>

<div id="lista_des">
<?php
$a= strip_tags($row_DatosPost['strContenido']);
echo substr($a,0,60)."...";
?>
</div>
</div>
<div id="coje_listados_fo">
<div id="lista_top_ri_dentro">
<div id="txt_dentro"><?php echo ObtenerNombreCategoria($row_DatosPost['intcategoria']); ?></div>
</div>
</div>

</div>
</div>
<?php } while ($row_DatosPost = mysql_fetch_assoc($DatosPost)); ?>
<?php } // Show if recordset not empty ?>
<?php if ($totalRows_DatosPost == 0) { // Show if recordset empty ?> y aqui muestra el mensaje porque no existe nada en el post//
No existe post ene esta categoria
<?php } // Show if recordset empty ?>


utiliza la funcion mostrar si, esta en comportamiento de servidor mostrar si los juegos de registros estan vacios
espero que te sirva
0
Puntos
Por bladedeybis hace 12 años
Developer
Respuesta #4
gracias bladedeybis, pero lo que me pasa es que al pulsar en una categoria que no tenga post, se me va a la pagina dtipica de "error al abrir url"
0
Puntos
Por borch hace 12 años
Developer
Respuesta #5
pues lo que te a respondido blade es válido a ver pon el enlace que te lleva a la pagina categorias
0
Puntos
Por zeuskx hace 12 años
Mods
Respuesta #6
lo que tengo en la de los botones que me lleva a las categorias es esto:
<div id="bloques">
	<div id="head_bloque">Todas las categor&iacute;as</div>
	<div id="lista_categoria"><a href="page/categorias.php?buscar=1">Desarrollo web: para desarrollar tu web</a></div>
    <div id="lista_categoria"><a href="page/categorias.php?buscar=2">Dise&ntilde;o gr&aacute;fico: desarrolla tu imaginaci&oacute;n</a></div>
    <div id="lista_categoria"><a href="page/categorias.php?buscar=3">Programaci&oacute;n: entiende las tripas de la web</a></div>
    <div id="lista_categoria"><a href="page/categorias.php?buscar=4&button=">Software: conoce los programas ma&aacute;s usados</a></div>
    
</div>
no funciona, no se que hacer!!
0
Puntos
Por borch hace 12 años
Developer
Respuesta #7
toma cambia tu pagina por esta
<?php require_once('../Connections/conexionforo.php'); 
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $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;
}
}

if (isset($_GET['buscar'])) {
$colname_Categoriafiltro = $_GET['buscar'];
}
mysql_select_db($database_conexionforo, $conexionforo);
$query_Categoriafiltro = sprintf("SELECT * FROM posts WHERE categoria=%s",$colname_Categoriafiltro,"int");
$Categoriafiltro = mysql_query($query_Categoriafiltro, $conexionforo) or die(mysql_error());
$row_Categoriafiltro = mysql_fetch_assoc($Categoriafiltro);
$totalRows_Categoriafiltro = mysql_num_rows($Categoriafiltro);
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title><?php echo $row_Datosweb['titulo']; ?></title>
<link rel="shortcut icon" type="image/x-icon" href="<?php echo $row_Datosweb['url']; ?>skins/default/img/favicon.ico">
<meta name="description" content="<?php echo $row_Datosweb['descripcion']; ?>">
<meta name="keywords" content="<?php echo $row_Datosweb['keywords']; ?>
">

<link href="../skins/default/css/estilos.css" rel="stylesheet" type="text/css">
</head>

<body>
<div id="contenedor">
  <div id="head">
   <div id="cabecera">
    <div id="logo"><a href="<?php echo $row_Datosweb['url']; ?>"><img src="../skins/default/img/logo.png" width="200" height="50" alt="logo"></a></div>
    <div id="buscador">
      <?php include("../includes/buscador.php"); ?>
    </div>
   </div>
  </div>
  <div id="menu">
    <?php include("../includes/menu.php"); ?>
    <?php include("../includes/usuarios.php"); ?>
  </div>
  <div id="cuerpo"><table width="100%" height="100%" border="0">
  <tr>
    <td width="100%" valign="top"><div id="izquierda">
    
    
   <?php  if ($row_Categoriafiltro!="") {?>
      <table width="100%" border="0" class="resultados">
        <tr>
          <td width="69%" class="tituloresultado"><a href="../<?php echo $row_Categoriafiltro['seo']; ?>.html"><?php echo $row_Categoriafiltro['titulo']; ?></a></td>
          <td width="31%" align="right"><span style="font-size:11px"><?php echo $row_Categoriafiltro['fecha']; ?></span></td>
        </tr>
        <tr>
          <td colspan="2">
          <?php // codigo para recortar los caracteres
		  $contenidocorto=($row_Categoriafiltro['mensajes']);
		  if ((strlen($contenidocorto))> 300) {	
		  $contenidocorto=substr($contenidocorto, 0, 85); 
		  }
		  echo $contenidocorto;include("../includes/leermas.php"); 
		  ?>
          </td>
          </tr>
      </table>
      <?php } else {?>
      <table width="100%" border="0" class="resultados">
        <tr>
          <td width="69%" class="tituloresultado"><h2>No hay post</h2></td>
          <td width="31%" align="right"><h2>No hay post</h2></td>
        </tr>
        <tr>
          <td colspan="2"><h2>No hay post</h2>
		</td>
          </tr>
      </table>
      <?php }?>
      
    </div></td>
    <td width="310" valign="top"><div id="derecha">
      <div id="bloques"><?php echo $row_Sacarextras['anuncio']; ?></div>
      <div id="bloques">
        <?php include("../includes/bloque_categorias.php"); ?>
        <?php include("../includes/bloque_comentarios.php"); ?>
    </div></td>
  </tr>
</table>
</div>
  <div id="footer">
  <?php include("../includes/footer.php"); ?>
</div>
</body>
</html>
<?php
mysql_free_result($Categoriafiltro);
?>
0
Puntos
Por zeuskx hace 12 años
Mods
Respuesta #8
pues me sigue pasando lo mismo, y no comprendo porquè!!
0
Puntos
Por borch hace 12 años
Developer
Respuesta #9
Cuando estoy en el index, la ruta que me dan los botones a las categorias es localhost/page/..... , pero cuandoestoy dentro de otro directorio, la ruta que me da es localhost/page/page/....., y tiene la ruta absoluta!! :(?????????
0
Puntos
Por borch hace 12 años
Developer
Respuesta #10
Mira Zeuskx, el boton q
0
Puntos
Por borch hace 12 años
Developer
Respuesta #11
Mira Zeuskx, el boton que va a las categorias lo tengo asi:

<div id="lista_categoria"><a href="page/categorias.php?buscar=1">Desarrollo web: para desarrollar tu web</a></div>

Si estoy en el index, perfecto, la ruta que coje es localhost/page/......, pero si estoy en otro directorio ya se jodió, si me meto en el directorio page, la ruta que coje es localhost/page/page/......, si voy a users toma como ruta localhost/users/page/......., He probado a quitar al boton el page/, pero nada,
no se como arreglarlo
0
Puntos
Por borch hace 12 años
Developer
Respuesta #12
imposible que tengas la url absoluta! por que la tienes así
<a href="page/categorias.php?buscar=1">
tienes que ponerla así
<a href="<?php echo $TuVariableDeUrl;?>page/categorias.php?buscar=1">
0
Puntos
Por zeuskx hace 12 años
Mods
Respuesta #13
joder!!! yo estoy ciego!!, perdona,
0
Puntos
Por borch hace 12 años
Developer
Respuesta #14
Ahora si va ok, mil gracias
0
Puntos
Por borch hace 12 años
Developer
Respuesta #15
xd no pasa nada tío cierro tema
0
Puntos
Por zeuskx hace 12 años
Mods
Para comentar Inicia sesión o Regístrate
Phpres 2025@ All rights reserved.
Utilizamos cookies para mejorar la navegación en el sitio. Más información Aceptar