Hola,
estoy con el proyecto de la carrera, un portal web de cocina, y quiero leer de una BD los ingredientes y mostrarlos, eso ok.
Pero para cada ingrediente hay una tabla con sus usos, para un ingrediente puede haber más de una fila con los usos, y quiero mostrarlos todos.
Yo tengo esto:
Código PHP:
// obtenemos los datos de los ingredientes
$consulta = "select * from ingredientes";
$ingredientes=mysql_query($consulta, $link);
$totingred=0;
if ($res_ingredientes= mysql_fetch_array($ingredientes)){
do {
$totingred++;
$nom_ingred = $res_ingredientes['nombre'];
$consulta_usos = "select * from ingred_usos where nombre = '$nom_ingred'";
$usos=mysql_query($consulta_usos, $link);
//guardo todos los usos que hay para ese ingrediente
if ($res_usos= mysql_fetch_array($usos)){
do {
$smarty -> append ('usos',array(
'ingred_uso'=> $res_usos['usos']
));
} while ($res_usos= mysql_fetch_array($usos));
}//if ($res_usos= mysql_fetch_array($usos))
$smarty -> append ('ingredientes',array(
'ingred_nombre'=> $res_ingredientes['nombre'],
'ingred_descrip'=> $res_ingredientes['descrip'],
));
} while ($res_ingredientes= mysql_fetch_array($ingredientes));
}// if ($res_ingredientes= mysql_fetch_array($ingredientes))
Y la plantilla es:
Código HTML:
<b>{$tot}</b>
<table class="tabla" style="width: 100%">
<tr>
{section name=i loop=$ingredientes}
<td class="titulocelda" colspan="2"> {$ingredientes[i].ingred_nombre}</td>
<tr>
<td class="derecha" style="width: 130px">Descripción:</td>
<td>{$ingredientes[i].ingred_descrip}</td>
</tr>
<tr>
<td class="derecha" style="width: 130px">Usos:</td>
{section name=j loop=$usos}
<td>{$usos[j].ingred_uso}</td>
{/section}
</tr>
<tr>
<td class="derecha" style="width: 130px">Nombres alternativos:</td>
{section name=k loop=$alternativas}
<td>{$alternativas[k].ingred_alter}</td>
{/section}
<tr>
<td class="celdavacia" colspan="3"> </td>
</tr>
{/section}
</table>
Pero así me salen todos los usos para todos los ingredientes,
sale esto:
http://al073568.al.nisu.org/ingredientes.php
Para "tomate" tendría que salir como usos "salsas" y para "arroz" usos "hacer harina"
¿A alguién se le ocurre como hacer esto? igual de orta manera....o algo...
gracias.