Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [Smarty] List/Menu ...
Luke
post
Post #1





Grupa: Przyjaciele php.pl
Postów: 215
Pomógł: 0
Dołączył: 28.10.2003
Skąd: -

Ostrzeżenie: (0%)
-----


Witam,

[php:1:985482a1f2]<?php
$rs = $db->GetAll("SELECT idArtykulu, tytul FROM pages");
?>[/php:1:985482a1f2]

wynikiem jest ...

Kod
Array ( [0] => Array ( [idArtykulu] => 1 [tytul] => Jakiś tam ) [1] => Array ( [idArtykulu] => 2 [tytul] => Jakiś tam ) )


Problem:

Z wynikow otrzymanych z bazy danych musze utworzyc List/Menu

[xml:1:985482a1f2]
<select name="_pageId" class="input">
<option label="{$idArtykulu}" value="{$idArtykulu}">{$tytul}</option>
</select>
[/xml:1:985482a1f2]

Nie znam Smarty na tyle dobrze aby poradzic sobie z tym problemem. Bardzo prosze o pomoc.

pozdrawiam


--------------------
<span style="font-weight: bold;">Open Source Enterprise Content Management</span>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 8)
HaRy
post
Post #2





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 15.05.2002
Skąd: Łódź

Ostrzeżenie: (0%)
-----


http://smarty.php.net/manual/en/language.f...ion.section.php


--------------------
Go to the top of the page
+Quote Post
rzseattle
post
Post #3





Grupa: Przyjaciele php.pl
Postów: 554
Pomógł: 0
Dołączył: 4.04.2002
Skąd: Tychy

Ostrzeżenie: (0%)
-----


w pliku php
[php:1:515fa7202c]<?php
$smarty->assign('artykuly',$rs);
?>[/php:1:515fa7202c]

w szablonie
[xml:1:515fa7202c]<select name="_pageId" class="input">
{foreach from=$artykuly item=curr_id }
<option label="{$curr_id.idArtykulu}" value="{$curr_id.idArtykulu}"> {$curr_id.tytul}
</option>
{foreachelse}
Nic nie ma.
{/foreach}
</select>[/xml:1:515fa7202c]


--------------------
"Real children don't go hoppity-skip unless they are on drugs."
Go to the top of the page
+Quote Post
Luke
post
Post #4





Grupa: Przyjaciele php.pl
Postów: 215
Pomógł: 0
Dołączył: 28.10.2003
Skąd: -

Ostrzeżenie: (0%)
-----


Tak, Hary: wiem, przeczytalem to ...

Mozesz to poprzec kawalkiem kodu?


--------------------
<span style="font-weight: bold;">Open Source Enterprise Content Management</span>
Go to the top of the page
+Quote Post
Luke
post
Post #5





Grupa: Przyjaciele php.pl
Postów: 215
Pomógł: 0
Dołączył: 28.10.2003
Skąd: -

Ostrzeżenie: (0%)
-----


Dziekuje rzseattle. Magiczna funkcja foreach ...


--------------------
<span style="font-weight: bold;">Open Source Enterprise Content Management</span>
Go to the top of the page
+Quote Post
HaRy
post
Post #6





Grupa: Zarejestrowani
Postów: 152
Pomógł: 0
Dołączył: 15.05.2002
Skąd: Łódź

Ostrzeżenie: (0%)
-----


Cytat
Tak, Hary: wiem, przeczytalem to ...

Mozesz to poprzec kawalkiem kodu?


alez prosze biggrin.gif
w php
[php:1:a9bcfea21a]<?php
$smarty -> assign("artykuly",$tablica);
?>[/php:1:a9bcfea21a]

a w tpl'u

Kod
<select name="_pageId" class="input">

{section loop=$artykuly name=name}

<option value="{$artykuly[name].idArtykulu}" label="{$artykuly[name].tytul}">{$artykuly[name].tytul}</option>

{sectionelse}

Pusta tablica.

{/section}

</select>


--------------------
Go to the top of the page
+Quote Post
DeyV
post
Post #7





Grupa: Zarząd
Postów: 2 277
Pomógł: 6
Dołączył: 27.12.2002
Skąd: Wołów/Wrocław




Manual jak zwykle górą


index.php:
[php:1:0e707ec1fc]<?php
require('Smarty.class.php');
$smarty = new Smarty;
$smarty->assign('cust_options', array(
1001 => 'Joe Schmoe',
1002 => 'Jack Smith',
1003 => 'Jane Johnson',
1004 => 'Charlie Brown'));

$smarty->assign('customer_id', 1001);
$smarty->display('index.tpl');?>[/php:1:0e707ec1fc]


index.tpl:
[xml:1:0e707ec1fc]<select name=customer_id>
{html_options options=$cust_options selected=$customer_id}
</select>[/xml:1:0e707ec1fc]

OUTPUT:
[xml:1:0e707ec1fc]<select name=customer_id>
<option value="1000">Joe Schmoe</option>
<option value="1001" selected="selected">Jack Smith</option>
<option value="1002">Jane Johnson</option>
<option value="1003">Charlie Brown</option>
</select>[/xml:1:0e707ec1fc]


--------------------
"Niezależnie od tego, jakie masz osiągnięcia, ktoś Ci pomaga..."
Go to the top of the page
+Quote Post
Luke
post
Post #8





Grupa: Przyjaciele php.pl
Postów: 215
Pomógł: 0
Dołączył: 28.10.2003
Skąd: -

Ostrzeżenie: (0%)
-----


DeyV: mam prosbe. Czy moglbys poprzec fragment z manuala, przykladowym kodem dla powyzszego problemu? Z uzyciem
Kod
{html_options options=$cust_options selected=$customer_id}
w .tpl


--------------------
<span style="font-weight: bold;">Open Source Enterprise Content Management</span>
Go to the top of the page
+Quote Post
DeyV
post
Post #9





Grupa: Zarząd
Postów: 2 277
Pomógł: 6
Dołączył: 27.12.2002
Skąd: Wołów/Wrocław




przepraszam, ale nie rozumiem pytania...
Przecież podałęm zarówno kod php jak i tpl, a nawet wynik działania...


--------------------
"Niezależnie od tego, jakie masz osiągnięcia, ktoś Ci pomaga..."
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 19.08.2025 - 04:09