|
Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon. |
|
View previous topic :: View next topic |
Author |
Message |
kenmasters Smarty n00b
Joined: 11 Feb 2008 Posts: 3
|
Posted: Mon Feb 11, 2008 6:09 am Post subject: duda con menus en DB |
|
|
Tengo una duda, digamos que deseo almacenar todo el varios bloques de menu dentro de una misma tabla en una base de datos de la siguiente manera por ejemplo:
TABLA : Menus, los campos son MENU, NOMBRE, URL y VISIBLE
MENU | NOMBRE | URL | VISIBLE
inicio home index.php si
inicio descargas descargas.php si
inicio noticias noti.php si
inicio donde donde.php si
menu2 porque pq.php si
menu2 quefue2 pq1.php si
menu2 adonde2 pq2.php si
menu2 nose3 pq3.php si
cuando haga una query a la base de datos seleccionar todo y usando el smarty ya sea con el foreach y con section leer los bloques de esa tabla de la siguiente manera, por ejemplo ( sin tener en cuando la cantidad de menus que sean..):
inicio
- home
- descarga
- noticias
- donde
menu2
- que fue
- a donde
- ... etc.. |
|
Back to top |
|
kenmasters Smarty n00b
Joined: 11 Feb 2008 Posts: 3
|
Posted: Thu Feb 21, 2008 3:37 am Post subject: Solucion |
|
|
PHP
Code: |
$tmp = mysql_query("SELECT * FROM Menus ORDER BY MENU");
while($row = mysql_fetch_array($tmp, MYSQL_ASSOC))
{
$menus[] = $row;
}
$smarty->assign('menus', $menus);
|
Template
Code: |
{assign var=lastmenu value=" "}
{foreach item=thismenu from=$menus}
{if $lastmenu ne $thismenu.MENU}
<br>{$thismenu.MENU}<br>
{assign var=lastmenu value=$thismenu.MENU}
{/if}
- {$thismenu.NAME}<br>
{/foreach}
|
|
|
Back to top |
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|