Foros del Web » Programando para Internet » PHP »

ayuda con <a> i consultas de varias tablas

Estas en el tema de ayuda con <a> i consultas de varias tablas en el foro de PHP en Foros del Web. tengo 2 links uno de categorías y otro de años y hago un while me salen todas las categorías y otro while todos los años ...
  #1 (permalink)  
Antiguo 23/02/2011, 14:04
 
Fecha de Ingreso: febrero-2009
Mensajes: 443
Antigüedad: 15 años, 2 meses
Puntos: 1
ayuda con <a> i consultas de varias tablas

tengo 2 links uno de categorías y otro de años
y hago un while me salen todas las categorías y otro while todos los años

me gustaría buscar por categoría y año al mismo tiempo en mysql ya tengo la consulta pero con links no se sise puede hacer

buscar por categoría ya me funciona
buscar por año ya me funciona
-buscar por categoría y año o año y categoría

y mas adelante categoría año y mes
categoría y mes
ano y mes
  #2 (permalink)  
Antiguo 23/02/2011, 14:13
Avatar de almagropaco_  
Fecha de Ingreso: marzo-2008
Ubicación: Mar del Plata
Mensajes: 854
Antigüedad: 16 años, 1 mes
Puntos: 25
Respuesta: ayuda con <a> i consultas de varias tablas

En la consulta prueba esto: WHERE categoria = '$categoria' AND año ='$año', obivamente adaptandolo a tu codigo...
Si no es asi, explica un poco mas y pon un poco del codigo para entender mejor.
  #3 (permalink)  
Antiguo 24/02/2011, 01:06
 
Fecha de Ingreso: febrero-2009
Mensajes: 443
Antigüedad: 15 años, 2 meses
Puntos: 1
Respuesta: ayuda con <a> i consultas de varias tablas

esta dividido en 5 partes las 2 primeras extraigo información de las base de datos y muestro el menú noticias y el menú año

tendria que modificar la validacion de la parte 3,4,5

-3 parte
muestro por noticias

me devuelve 2 tablas una de nuevos productos i otra
muestra error porque me coge la parte 5 y me dice que falta un parámetro que seria año


-4 parte
muestro por años



-5 parte mostrar por noticia y año
tengo problemas en esta parte
tanto en validación como mostrar el resultado
la url tendría que ser así /*categoria_id=nuevos_productos&año_id=2010*/

tengo un else porque con esta condición nunca entrara if($_GET[categoria_id] == true AND $_GET[año_id] == true)



Código PHP:
<html>
    <head></head>
    <body>
         <link rel="stylesheet" type="text/css"  media="screen" href="a.css" /><!-- css -->

<?php
/*echo $_GET[categoria_id]."</br>";*/
echo '<div id="menu_izquierda">';

    echo 
'<div id="noticies_menu"><h3>Notícies</h3>';
    
$link mysqli_connect("localhost","a","b",&#8221;c");
    
$query "SELECT * FROM categories ORDER BY categoria_id DESC";
    
mysqli_query ($link,'SET NAMES "utf8" ');
    
$result mysqli_query($link,$query);
    
/*while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){*/
    /*echo $row['categoria_id'];*/



    
echo "<ul>";
        while(
$row mysqli_fetch_array($result,MYSQLI_ASSOC))
        {
           
/*if($categoria_id != 0){*/
         
echo "<li><a href=noticies.php?categoria_id=" $row["categoria_id"]  . "><strong>"str_replace("_"," ",ucfirst($row["categoria_id"])) . "</strong></a> ";
           
/*}*/
         
$query1 "SELECT COUNT(*) AS 'Total Categorias' FROM noticias INNER JOIN categories ON noticias.categoria_id=categories.categoria_id WHERE categories.categoria_id="."'$row[categoria_id]'"." GROUP BY categories.categoria_id";
         
mysqli_query ($link,'SET NAMES "utf8" ');
         
$result1 mysqli_query($link,$query1);
         
$row mysqli_fetch_array($result1MYSQLI_ASSOC);
         echo 
$row['Total Categorias']."</li>";
      
        
        }
    echo 
"<ul/>";


            

    
$query2="SELECT COUNT(*) AS 'Total Noticias' FROM noticias";
    
$result2 mysqli_query($link$query2);
    
$row mysqli_fetch_array($result2MYSQLI_ASSOC);
    echo 
"Total Notícias: ";echo $row["Total Noticias"];


/*}*/

/* free result set */
mysqli_free_result($result);

/* close connection */
mysqli_close($link);
    echo 
'</div>';

Código PHP:
    echo '<div id="noticias_año"><h3>Año</h3>';
    
$link mysqli_connect("localhost","a","b","c");
    
$query3 "SELECT * FROM años";
    
mysqli_query ($link,'SET NAMES "utf8" ');
    
$result mysqli_query($link,$query3);
    
/*while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
        echo $row['año_id'];
    }*/
    
echo "<ul>";
        while(
$row mysqli_fetch_array($result,MYSQLI_ASSOC))
        {
            echo 
"<li><a href=noticies.php?año_id=" $row["año_id"] .  "><strong>"ucfirst($row["any_id"]) . "</strong></a> ";
            
$query4 ="SELECT COUNT(*) AS 'Total fecha',EXTRACT(YEAR FROM noticias.noticia_fecha) FROM noticies  WHERE YEAR(noticies.noticia_fecha)="."'$row[any_id] '"."GROUP BY EXTRACT(YEAR FROM noticias.noticia_fecha)";
            
mysqli_query ($link,'SET NAMES "utf8" ');
            
$result4 mysqli_query($link,$query4);
            
$row mysqli_fetch_array($result4MYSQLI_ASSOC);
            echo 
$row['Total fecha']."</li>";
        }
    echo 
"<ul/>";
    
$query2="SELECT COUNT(*) AS 'Total Noticias Año' FROM noticias";
    
$result2 mysqli_query($link$query2);
    
$row mysqli_fetch_array($result2MYSQLI_ASSOC);
    echo 
"Total Notícias Año: ";echo $row["Total Noticias Año"];



    
/* free result set */
    
mysqli_free_result($result);

    
/* close connection */
    
mysqli_close($link);
    echo 
'</div>';
echo 
'</div>'



















Código PHP:

 
if($_GET[categoria_id] == true){
 
$link mysqli_connect("localhost","a","b","c");
         
$query6 =  "SELECT categories.categoria_id,noticies.noticia_titulo,noticies.noticia_fecha,noticies.noticia_foto_pequeña,noticies.noticia_foto_grande,noticies.noticia_descripcion
                    FROM categories INNER JOIN  noticies
                    ON categories.categoria_id = noticies.categoria_id
                    WHERE categories.categoria_id="
."'$_GET[categoria_id]'".";";
         echo 
$query6;
         
mysqli_query ($link,'SET NAMES "utf8" ');
         
$result mysqli_query($link,$query6);



         
/* associative array */
         
echo '<div id="noticies">';
            
$contador 1;
            while(
$row mysqli_fetch_array($result,MYSQLI_ASSOC))
         {
                echo 
'<div id="noticies_categories">';
                if(
$contador == 1)
                {
                    echo 
"<h1>".str_replace("_"," ",ucfirst($row['categoria_id']))."</h1>";
                }
                echo 
'</div>';

            

                echo 
'<div id="noticia_titulo">';
                    echo 
"<h2>".ucfirst($row['noticia_titulo'])."</h2>";
                echo 
'</div>';

                echo 
'<div id="noticies_fecha">';
                    echo 
"<h3>".$row['noticia_fecha']."</h3>";
                echo 
'</div>';

                echo 
'<div id="noticia_foto_grande">';
                    echo 
$row['noticia_foto_grande'];
                echo 
'</div>';

                echo 
'<div id="noticia_descripcion">';
                    echo 
"<p><strong>".$row['noticia_descripcion']."</strong></p>";
                echo 
'</div><hr/>';
            
$contador++;
         }
        
         echo 
'</div>';

         
/* free result set */
mysqli_free_result($result);

/* close connection */
mysqli_close($link);




Código PHP:
  if($_GET[any_id] == true){
 
$link mysqli_connect("localhost","a","b","c");
         
$query5 =  "SELECT categories.categoria_id,noticies.noticia_titulo,noticies.noticia_data,EXTRACT(YEAR FROM noticies.noticia_fecha) AS noticies_año,noticies.noticia_foto_pequeña,noticies.noticia_foto_grande,noticies.noticia_descripcion
                    FROM categories INNER JOIN  noticies
                    ON categories.categoria_id = noticies.categoria_id
                    WHERE YEAR(noticies.noticia_fecha)="
."$_GET[any_id]".";";
         echo 
$query5;
         
mysqli_query ($link,'SET NAMES "utf8" ');
         
$result mysqli_query($link,$query5);

         
/* associative array */
         
echo '<div id="noticies">';
         
$contador 1;
            while(
$row mysqli_fetch_array($result,MYSQLI_ASSOC))
         {
              
                   echo 
'<div id="noticies_fecha">';
                if(
$contador == 1)
                {
                    echo 
"<h1>".$row['noticies_año']."</h1>";
                }
                echo 
'</div>';
             
                echo 
'<div id="noticies_categories">';

                echo 
"<h2>".str_replace("_"," ",ucfirst($row['categoria_id']))."</h2>";

                echo 
'</div>';
          
                echo 
'<div id="noticies_titulo">';
                    echo 
"<h3>".ucfirst($row['noticia_titulo'])."</h3>";
                echo 
'</div>';

                echo 
'<div id="noticies_fecha">';
                    echo 
"<h4>".$row['noticia_fecha']."</h4>";
                echo 
'</div>';

                echo 
'<div id="noticia_foto_grande">';
                    echo 
$row['noticia_foto_grande'];
                echo 
'</div>';

                echo 
'<div id="noticia_descripcion">';
                    echo 
"<p><strong>".$row['noticia_descripcion']."</strong></p>";
                echo 
'</div><hr/>';
         
$contador++;
         }
       
         echo 
'</div>';

         
/* free result set */
        
mysqli_free_result($result);

        
/* close connection */
        
mysqli_close($link);

Código PHP:




else{

 echo 
"<a href=noticies.php?categoria_id=" $row["categoria_id"]  ."&año_id".$row["año_id"]. "></a> ";

$link mysqli_connect("localhost","a","b","c");
         
$query5 =  "SELECT categories.categoria_id,noticies.noticia_titulo,noticies.noticia_fecha,noticies.noticia_foto_pequeña,noticies.noticia_foto_grande,noticies.noticia_descripcion
                    FROM categories INNER JOIN  noticies
                    ON categories.categoria_id = noticies.categoria_id
                    WHERE categories.categoria_id="
."'$_GET[categoria_id] and YEAR(noticies.noticia_data)=".$_GET[any_id].";";
         
mysqli_query ($link,'SET NAMES "utf8" ');
         
$result mysqli_query($link,$query5);

 
/* associative array */
         
echo '<div id="noticias">';
            
$contador 1;
            while(
$row mysqli_fetch_array($result,MYSQLI_ASSOC))
         {

                echo 
'<div id="noticia_categorias">';
                if(
$contador == 1)
                {
                    echo 
"<h1>".str_replace("_"," ",ucfirst($row['categoria_id']))."</h1>";
                }
                echo 
'</div>';

              

                echo 
'<div id="noticies_titulo">';
                    echo 
"<h2>".ucfirst($row['noticia_titulo'])."</h2>";
                echo 
'</div>';

                echo 
'<div id="noticies_fecha">';
                    echo 
"<h3>".$row['noticia_fecha']."</h3>";
                echo 
'</div>';

                echo 
'<div id="noticia_foto_grande">';
                    echo 
$row['noticia_foto_grande'];
                echo 
'</div>';

                echo 
'<div id="noticia_descripcion">';
                    echo 
"<p><strong>".$row['noticia_descripcion']."</strong></p>";
                echo 
'</div><hr/>';
            
$contador++;
         }

         echo 
'</div>';



}








        
?> 

Última edición por albertrc; 24/02/2011 a las 01:26

Etiquetas: tablas
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 00:10.