Mysql
 sql >> Base de Dados >  >> RDS >> Mysql

array multidimensional php gerado a partir do banco de dados


Ok, depois de fazer a pesquisa encontrei a solução (TÃO FÁCIL, MAS QUANDO NUNCA PRECISA.....)
      $selectors_array = array();
      $selector_query = tep_db_query("SELECT * FROM bts_selectors");
      while ($selector = tep_db_fetch_array($selector_query)) {
      $selectors_array[] = array('id' => $selector['id'], 
                             'selector' => $selector['selector']
                             );
    }

    $css = '';
    foreach ( $selectors_array as $selector ) { 
    $rules = '';

    $properties_query = tep_db_query("SELECT * FROM bts_properties WHERE selector_id = '" . $selector['id'] . "' ");

   while ($properties = tep_db_fetch_array($properties_query)) {    
    $rules .= "\n \t$properties[css_el]:$properties[css_val];";
    }
        $css .= "$selector[selector]".'{'."$rules \n".'}'."\n\n";
    }

    echo "<pre>";
    echo "$css";
    echo "</pre>";
";
Saída gerada e desejada:
.thisone{
border:1px solid;
padding:10px; 
}

#thatone{
border:1px solid; 
}

.body{
width:40px;
height:40px; 
}