Ver Mensaje Individual
  #3 (permalink)  
Antiguo 09/02/2010, 20:45
Avatar de jartaud
jartaud
 
Fecha de Ingreso: octubre-2009
Ubicación: Canal de Panamá
Mensajes: 96
Antigüedad: 14 años, 6 meses
Puntos: 2
Respuesta: Ayuda con display PHP MySQL

Funciona bien su coodigo, cuando lo aplico a las categorias o subcategorias:

Computer---------------Electronic --------------------- Services

Pero como puedo obtener:

Computer ----------------------- Electronic
PC------------------------------MP3


Código PHP:
//Sacar las categorias
$cat = mysql_query("SELECT * FROM cat_ad order by $cat_name") or die(mysql_error());
       while($row_parent = mysql_fetch_array($cat)){
           
           
//Sacar las subcategorias
$subcat = mysql_query("SELECT * FROM sub_cat_ad WHERE from_cat_ad = '".$row_parent['idCat_ad']."'") or die(mysql_error());
        

$count = mysql_num_rows($subcat);

//Si no hay una relacion entre cat y sub cat   imprimimos la categoria
 if($count == 0){?>
<h2><a href="#"><?php echo htmlspecialchars($row_parent[$cat_name]);?></a></h2>
            <?php }else{?>

//Sino imprimimos las cat y sus subcat
<h2><?php echo htmlspecialchars($row_parent[$cat_name]);?></h2>   
                <?php while($row_child mysql_fetch_array($subcat)){?>
                       <a href="#"><?php echo htmlspecialchars($row_child[$subcatName])." ,";?></a>
            <?php }}}?>