Hola amigos que tal estan.
Miren estoy haciendo un blog nuy basico y la verdad es que quiero poder filtrar los datos que se muestan en una página llamada "blog.php".
Por otro lado tengo una tabla llamada "blog" esta tabla contiene un campo llamado estado. y en ella puede contener dos posibles valores "No publicado" o "Publicado".
entonces quiero hacer una consulta sql que me liste en la web solo los que en el campo estado esten como "publicado"

Este es un resumen de la consulta
SELECT *
FROM blog_detalle
WHERE blog_detalle.Estado= Publicado
ORDER BY blog_detalle.idBlog DESC

La consulta completa es esta. Pero tiene errores
<?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;
}
}

$currentPage = $_SERVER["PHP_SELF"];

$maxRows_JuegoDeRegistro = 10;
$pageNum_JuegoDeRegistro = 0;
if (isset($_GET['pageNum_JuegoDeRegistro'])) {
  $pageNum_JuegoDeRegistro = $_GET['pageNum_JuegoDeRegistro'];
}
$startRow_JuegoDeRegistro = $pageNum_JuegoDeRegistro * $maxRows_JuegoDeRegistro;

mysql_select_db($database_treboles, $treboles);
$query_JuegoDeRegistro = "SELECT * FROM blog_detalle";
$query_limit_JuegoDeRegistro = sprintf("%s LIMIT %d, %d", $query_JuegoDeRegistro, $startRow_JuegoDeRegistro, $maxRows_JuegoDeRegistro);
$JuegoDeRegistro = mysql_query($query_limit_JuegoDeRegistro, $treboles) or die(mysql_error());
$row_JuegoDeRegistro = mysql_fetch_assoc($JuegoDeRegistro);

if (isset($_GET['totalRows_JuegoDeRegistro'])) {
  $totalRows_JuegoDeRegistro = $_GET['totalRows_JuegoDeRegistro'];
} else {
  $all_JuegoDeRegistro = mysql_query($query_JuegoDeRegistro);
  $totalRows_JuegoDeRegistro = mysql_num_rows($all_JuegoDeRegistro);
}
$totalPages_JuegoDeRegistro = ceil($totalRows_JuegoDeRegistro/$maxRows_JuegoDeRegistro)-1;

$queryString_JuegoDeRegistro = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_JuegoDeRegistro") == false && 
        stristr($param, "totalRows_JuegoDeRegistro") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_JuegoDeRegistro = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_JuegoDeRegistro = sprintf("&totalRows_JuegoDeRegistro=%d%s", $totalRows_JuegoDeRegistro, $queryString_JuegoDeRegistro);
?>
Por favor ayudenme es muy importante.
Saludos y muchas gracias.
5
Puntos
14268
Visitas
3
Resp
Por tokens hace 11 años
Novice
Respuesta #1
Hola tokens, pero en la consulta que colocas no tiene el condicional WHERE. ¿Que errores tiene? ¿No te filtra? Esta línea debería ser
$query_JuegoDeRegistro = "SELECT * FROM blog_detalle WHERE Estado='Publicado' ";
Publicado debe tener las comillas. Ya que se trata de un texto. Y bueno yo hice un blog también con ese mismo sistema pero lo trabajo con valores numéricos 1 y 0 (0 Para oculto y 1 para publicado). Creo que es mejor xd
5
Puntos
Por jose hace 11 años
Master
Respuesta #2
pero con esto deberia bastar asi.
SELECT *
FROM blog_detalle
WHERE blog_detalle.Estado= Publicado
ORDER BY blog_detalle.idBlog DESC
y asi sacarua solo lo que correspondem,
+
0
Puntos
Por tokens hace 11 años
Novice
Respuesta #3
Bueno, reemplaza lo que está en $query_JuegoDeRegistro por eso
$query_JuegoDeRegistro = sprintf(

"SELECT *
FROM blog_detalle
WHERE blog_detalle.Estado= 'Publicado'
ORDER BY blog_detalle.idBlog DESC"

);
5
Puntos
Por jose hace 11 años
Master
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