Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Mehrschichtiges Array mit Tabellenausgabe

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German
View previous topic :: View next topic  
Author Message
avataroflive
Smarty Rookie


Joined: 03 Jul 2013
Posts: 6

PostPosted: Wed Jul 03, 2013 6:34 am    Post subject: Mehrschichtiges Array mit Tabellenausgabe Reply with quote

Hallo,
habe ein großes Problem mit meinem Array und der Ausgabe. Ausgegeben sollen in einer Tabelle nebeneinander der Farbname(in der zugewiesen Farbe) sowie die drei Farben. Leider finde ich derzeit keine brauchbare Lösung in verbinung mit Smarty.
Derzeitiger Stand : http://fygo.de/farben.php

PHP
Code:

$farbarr = array();
while ($row = mysql_fetch_array($ergebnis)) {
// Auswahl der Namensprache
switch ($_SESSION['sprache']) {
    case de:
        $farben_name = $row['name_de'];
        break;
    case fr:
        $farben_name = $row['name_fr'];
        break;
    case es:
        $farben_name = $row['name_es'];
        break;
    case us:
        $farben_name = $row['name_us'];
        break;

       }
// Farbgebung Namen der Farben
switch ($row['seltenheit']) {
    case e:
        $seltenheit = '#2ECCFA';
        break;
    case m:
        $seltenheit = '#40FF00';
        break;
    case s:
        $seltenheit = '#D7DF01';
        break;
    case xs:
        $seltenheit = '#000000';
        break;
    case a:
        $seltenheit = '#A4A4A4';
        break;
       }


$wert1['seltenheit'] = $seltenheit;
$farbarr[] = $wert1;
$wert1['farbname'] = $farben_name;
$farbarr[] = $wert1 ;
$wert1['leicht'] = RGBToHex($row['Rot_leicht'],$row['Blau_leicht'],$row['Grun_leicht']);
$farbarr[] = $wert1  ;
$wert1['leder'] = RGBToHex($row['Rot_leather'],$row['Blau_leather'],$row['Grun_leather']);
$farbarr[] = $wert1 ;
$wert1['metal'] = RGBToHex($row['Rot_metal'],$row['Blau_metal'],$row['Grun_metal']);


}

$smarty->assign('farbwert',$farbarr);[url]


TPL
Code:
<div id="farbe_inhalt">
    <table class="reference notranslate">
       {foreach $farbwert as $farbarr1}
   <tr>
    <td style="color: {$farbarr1['seltenheit']}  ">{$farbarr1['farbname']}</td>

    <td bgcolor="{$farbarr1[leicht]}">&nbsp;</td>

    <td bgcolor="{$farbarr1[leder]}">&nbsp;</td>

    <td bgcolor="{$farbarr1[metal]}">&nbsp;</td>
  </tr>
   {/foreach}
   </table>
        </div>


Hoffe jemand hat da noch ne Eingebung Wink
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Jul 03, 2013 7:03 am    Post subject: Reply with quote

Hey versuch mal statt das hier:

Code:

$wert1['seltenheit'] = $seltenheit;
$farbarr[] = $wert1;
$wert1['farbname'] = $farben_name;
$farbarr[] = $wert1 ;
$wert1['leicht'] = RGBToHex($row['Rot_leicht'],$row['Blau_leicht'],$row['Grun_leicht']);
$farbarr[] = $wert1  ;
$wert1['leder'] = RGBToHex($row['Rot_leather'],$row['Blau_leather'],$row['Grun_leather']);
$farbarr[] = $wert1 ;
$wert1['metal'] = RGBToHex($row['Rot_metal'],$row['Blau_metal'],$row['Grun_metal']);


lieber das hier:

Code:

array_push($farbarr, array("seltenheit" => $seltenheit,
                     "farbname" => $farben_name,
                     "leicht" => RGBToHex($row['Rot_leicht'],$row['Blau_leicht'],$row['Grun_leicht'])
                     "leder" => RGBToHex($row['Rot_leather'],$row['Blau_leather'],$row['Grun_leather']),
                     "metal" => RGBToHex($row['Rot_metal'],$row['Blau_metal'],$row['Grun_metal']));


Und im template dann das:

Code:

{foreach from=$farbwert item=wert key=k}
   <tr>
    <td style="color: {$wert.k.seltenheit}  ">{$wert.k.farbname}</td>

    <td bgcolor="{$wert.k.leicht}">&nbsp;</td>

    <td bgcolor="{$wert.k.leder}">&nbsp;</td>

    <td bgcolor="{$wert.k.metal}">&nbsp;</td>
  </tr>
{/foreach}
Back to top
View user's profile Send private message Visit poster's website
avataroflive
Smarty Rookie


Joined: 03 Jul 2013
Posts: 6

PostPosted: Wed Jul 03, 2013 7:33 am    Post subject: Reply with quote

Danke sieht schon nicht schlecht aus, hat zwar nen komma und ne klammer gefehlt aber das array sieht gut aus nur die ausgabe ist leider leer. Schau mir das nachher nochmal an muss erstmal weg. Aber danke nochmals für den tip
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Wed Jul 03, 2013 9:01 am    Post subject: Reply with quote

Oh sorry, stimmt. Habs erstmal einfach getippt ohne es auszuprobieren...
Back to top
View user's profile Send private message Visit poster's website
avataroflive
Smarty Rookie


Joined: 03 Jul 2013
Posts: 6

PostPosted: Wed Jul 03, 2013 4:35 pm    Post subject: Reply with quote

Ok Fehler gefunden .k war zu viel. Jetzt gehts soweit. Neues Problem ist wie bekomme ich das ganze jetzt hin das es blätterbare seiten werden? Davon habe ich leider gleich mal null ahnung.
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Thu Jul 04, 2013 6:58 am    Post subject: Reply with quote

Was meinst du mit "Blätterbare" Seiten? Meinst du dass z. B. 10 Elemente angezeigt werden und dann unten auf die Seite 2 verwiesen werden kann um die nächsten 10 Elemente anzuzeigen!?
Back to top
View user's profile Send private message Visit poster's website
avataroflive
Smarty Rookie


Joined: 03 Jul 2013
Posts: 6

PostPosted: Thu Jul 04, 2013 7:00 am    Post subject: Reply with quote

ja genau, bin schon am bauen aber da alles seiten über toggleswitch angezeigt werden funktionieren schon mal keine get befehle. gar net so einfach
Back to top
View user's profile Send private message
Grizzly
Smarty Pro


Joined: 15 Apr 2011
Posts: 172
Location: Germany

PostPosted: Thu Jul 04, 2013 7:13 am    Post subject: Reply with quote

Naja du brauchst erstmal eine aktuelle Seitenanzahl, dein maximale Anzahl an anzuzeigenden Seiten und du musst dann aus der DB nicht alle Elemente holen, sondern nur die maximal anzuzeigende Anzahl.

Vorgehen:
1. Zähle alle Elemente aus der DB ==>
Code:
$totalItems = SELECT COUNT( * ) FROM xyz


2. Bestimme die Aktuelle Seitenzahl, wenn die übergebene Seitenzahl größer ist als die maximale Seitenanzahl variable, dann ist die aktuelle Seite = 1
Code:

$pageNumber = ceil($totalItems / $itemsPerPage) < $pageNumber ? 1 : $pageNumber;


3. Bestimme ab wann die Elemente geholt werden sollen:

Code:
$sqlLimitStart = ($pageNumber - 1) * $itemsPerPage; //-1 weil 0 basiert


4. Hole dir die (Anzahl pro Seite) Elemente aus der DB

Code:
$allItems = "SELECT * FROM xyz LIMIT $sqlLimitStart, $itemsPerPage


Iteriere im Template die $allItems durch und stelle sie dar...
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Language: German All times are GMT
Page 1 of 1

 
Jump to:  
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
Protected by Anti-Spam ACP