Ver Mensaje Individual
  #1 (permalink)  
Antiguo 30/06/2011, 11:58
Avatar de dvbeaumont
dvbeaumont
 
Fecha de Ingreso: marzo-2011
Ubicación: Caracas
Mensajes: 145
Antigüedad: 14 años
Puntos: 1
Pregunta Mostrar registros concatenados

Hola! tengo un menú que se maneja de la siguiente forma.

Las partes del menú son:
  • Tipo
  • Subtipo
  • Marca
  • Modelo

Las tablas son así.

Código MySQL:
Ver original
  1. `t_tipo` (
  2.   `id_tipo` int(11) NOT NULL auto_increment,
  3.   `ti_name` varchar(25) NOT NULL,
  4.   `ti_estatus` tinyint(4) NOT NULL,
  5.   PRIMARY KEY  (`id_tipo`)
  6. )

Código MySQL:
Ver original
  1. `t_subtipo` (
  2.   `id_subtipo` int(10) unsigned NOT NULL auto_increment,
  3.   `id_tipo` int(11) NOT NULL,
  4.   `su_name` char(150) NOT NULL,
  5.   `su_estatus` int(10) unsigned NOT NULL
  6.   PRIMARY KEY  (`id_subtipo`)
  7. )

Código MySQL:
Ver original
  1. `t_marca` (
  2.   `id_marca` int(10) unsigned NOT NULL auto_increment,
  3.   `ma_name` char(150) NOT NULL,
  4.   `ma_estatus` int(11) default NULL
  5.   PRIMARY KEY  (`id_marca`)
  6. )

Código MySQL:
Ver original
  1. `t_modelos` (
  2.   `id_modelo` int(10) unsigned NOT NULL auto_increment,
  3.   `id_tipo` int(10) NOT NULL,
  4.   `id_subtipo` int(10) NOT NULL,
  5.   `id_marca` int(11) NOT NULL,
  6.   `mo_titulo` char(150) NOT NULL
  7.   PRIMARY KEY  (`id_modelo`)
  8. )

Explico!

La tabla tipo es la principal
Subtipo pertenece al Tipo, o sea debe obtener su id
La tabla Marca no posee a ninguno (no se a cual unirlo)
La tabla modelo posee a los 3

La forma en la que estoy haciendo la llamada es la siguiente:


Código PHP:
Ver original
  1. <?php
  2.   include("admin/conexion2.php");
  3.    $linke=conectar2();
  4.    $result_a=mysql_query("select * from t_tipo ORDER BY id_tipo",$linke);
  5.    while($row_a = mysql_fetch_array($result_a)) {
  6.                     echo " <li><a href='#'>".$row_a["ti_name"]."</a>
  7.                     <ul class='horizontal'>";
  8.         $tipo=$row_a["id_tipo"];           
  9.    $result_d=mysql_query("select * from t_subtipo WHERE id_tipo=".$tipo." ORDER BY id_tipo",$linke);
  10.    while($row = mysql_fetch_array($result_d)) {
  11.                     echo "
  12.                         <li><a href='#'>".$row["su_name"]."</a>";
  13.                         echo"<div class='extended'>";
  14.                         echo"<ul class='smallNav'>";
  15.         $result_m=mysql_query("select * from t_marca ORDER BY id_marca",$linke);
  16.    while($row_m = mysql_fetch_array($result_m)) {
  17.                   $subtipo=$row["id_subtipo"];
  18.                   $marca=$row_m["id_marca"];
  19.                   $result_e=mysql_query("select * from t_modelos WHERE id_subtipo=".$subtipo." AND id_marca=".$marca." ORDER BY id_modelo ;",$linke)  or die( "Error en query: $linke, el error  es: " . mysql_error() );  
  20.         while ($row_e = mysql_fetch_array($result_e)){
  21.                 $desat=" ";
  22. if ($row_e["id_marca"]=='4'){ $desat.="<a href='index2.php'><img src='images/marca-1.png'  height='30' align='center'  border='0'/>"; }
  23. if ($row_e["id_marca"]=='5'){ $desat.="<a href='index2.php'><img src='images/marca-2.png'  height='30' align='center'  border='0'/>"; }
  24. if ($row_e["id_marca"]=='6'){ $desat.="<a href='index2.php'><img src='images/marca-3.png'  height='30' align='center'  border='0'/>"; }
  25. if ($row_e["id_marca"]=='7'){ $desat.="<a href='index2.php'><img src='images/marca-4.png'  height='30' align='center'  border='0'/>"; }
  26. if ($row_e["id_marca"]=='8'){ $desat.="<a href='index2.php'><img src='images/marca-5.png'  height='30' align='center'  border='0'/>"; }
  27. if ($row_e["id_marca"]=='9'){ $desat.="<a href='index2.php'><img src='images/marca-6.png'  height='30' align='center'  border='0'/>"; }
  28. if ($row_e["id_marca"]=='10'){ $desat.="<a href='index2.php'><img src='images/marca-7.png'  height='30' align='center'  border='0'/>"; }
  29. if ($row_e["id_marca"]=='11'){ $desat.="<a href='index2.php'><img src='images/marca-8.png'  height='30' align='center'  border='0'/>"; }
  30. if ($row_e["id_marca"]=='12'){ $desat.="<a href='index2.php'><img src='images/marca-9.png'  height='30' align='center'  border='0'/>"; }
  31. if ($row_e["id_marca"]=='13'){ $desat.="<a href='index2.php'><img src='images/marca-10.png'  height='30' align='center'  border='0'/>"; }
  32. if ($row_e["id_marca"]=='14'){ $desat.="<a href='index2.php'><img src='images/marca-11.png'  height='30' align='center'  border='0'/>"; }
  33.  
  34.         echo"<li><b style='font-size:14px'>".$desat."</b></li>";
  35.        
  36.     } }
  37.    echo"</ul></div></li>";}
  38.    
  39.    echo"</ul>
  40.                 </li>";}  
  41. ?>

El problema es el siguiente! cuando tengo modelos cargados entonces aparecen siempre la marca. Quiero que salga una sola vez la marca y despues salgan los modelos (la cantidad que sean) no que se repitan las marcas siempre.

Gracias de antemano!