|
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 |
Philipp_Frank Smarty Rookie
Joined: 24 Oct 2004 Posts: 6
|
Posted: Thu Nov 04, 2004 11:51 am Post subject: while-schleife nochmal |
|
|
Code: |
$query = mysql_query("SELECT name FROM kategorien ORDER by ID DESC");
if (mysql_affected_rows () > 0)
{
while ($result = mysql_fetch_array($query))
{
echo '<option value="'.$result[name].'">'.$result[name].'</option>';
}
}
|
Wie löse ich das in smarty[/code] |
|
Back to top |
|
messju Administrator
Joined: 16 Apr 2003 Posts: 3336 Location: Oldenburg, Germany
|
Posted: Thu Nov 04, 2004 12:06 pm Post subject: Re: while-schleife nochmal |
|
|
Code: |
$query = mysql_query("SELECT name FROM kategorien ORDER by ID DESC");
$options = array();
while ($result = mysql_fetch_array($query))
{
$options[$result['name']] = $result['name'];
}
$smarty->assign('options', $options);
|
Code: |
{html_options options=$options}
|
|
|
Back to top |
|
Philipp_Frank Smarty Rookie
Joined: 24 Oct 2004 Posts: 6
|
Posted: Thu Nov 04, 2004 2:51 pm Post subject: |
|
|
danke, funzt, und nun eine zweite frage, wenn ich nun eine while schleife in einer anderen wihile schleife machen will. Also in der erstel whileschleife alle kategorien und in der zweiten alle subkategorien ... wie funztn des ? |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Thu Nov 04, 2004 2:53 pm Post subject: |
|
|
Philipp_Frank wrote: | danke, funzt, und nun eine zweite frage, wenn ich nun eine while schleife in einer anderen wihile schleife machen will. Also in der erstel whileschleife alle kategorien und in der zweiten alle subkategorien ... wie funztn des ? |
kommt drauf an wie du es ausgeben willst.
Einfach 2 Select boxen?
[php:1:ead8f5127b]
$query = mysql_query("SELECT name FROM kategorien ORDER by ID DESC");
$options = array();
while ($result = mysql_fetch_array($query))
{
$options[$result['name']] = $result['name'];
}
$smarty->assign('options', $options);
$query = mysql_query("SELECT name FROM subkategorien ORDER by ID DESC");
$options = array();
while ($result = mysql_fetch_array($query))
{
$options[$result['name']] = $result['name'];
}
$smarty->assign('suboptions', $options);
[/php:1:ead8f5127b]
Code: |
{html_options options=$options}
{html_options options=$suboptions}
|
|
|
Back to top |
|
Philipp_Frank Smarty Rookie
Joined: 24 Oct 2004 Posts: 6
|
Posted: Thu Nov 04, 2004 3:17 pm Post subject: |
|
|
axo hab ich vergessen zu sagen, net in selectboxen, sondern als text
also:
Hauptkat1
Subkat1
Subkat2
Hauptkat2
Subkat4
Subkat5
Hauptkategorie: SELECT name FROM kategorien WHERE type = 'kat'
Subkat.: SELECT name FROM kategorien WHERE type = 'subkat' AND hauptkat = 'Hauptkategorie->name' |
|
Back to top |
|
kills Smarty Elite
Joined: 28 May 2004 Posts: 493
|
Posted: Thu Nov 04, 2004 6:56 pm Post subject: |
|
|
[php:1:5ac2986e4d]
$query = mysql_query("SELECT name FROM kategorien ORDER by ID DESC"); // hier muss wahrscheinlich noch hin WHERE type='mainkat' ?
$cats = array();
$i = 0;
while ($result = mysql_fetch_array($query))
{
$cat = $result['name'];
$cats[$i]['name'] = $cat;
$cats[$i]['subcats'] = array();
$query2 = mysql_query("SELECT name FROM kategorien WHERE type = 'subkat' AND hauptkat ='".$cat."'");
while ($result2 = mysql_fetch_array($query2))
{
$cats[$i]['subcats'][] = $result2['name'];
}
$i++;
}
$smarty->assign('cats', $cats);
[/php:1:5ac2986e4d]
Code: |
{ foreach from=$cats item="maincat" }
<b>{$maincat.name}</b>
{ foreach from=$maincat.subcats item="subcat" }
{ $subcat }
{ /foreach }
{ /foreach}
|
ungetestet!
aber für sowas nimmt man besser 2 Tabelle. Dann brauch man nur einen select machen. |
|
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
|