Ergebnis 1 bis 6 von 6

Thema: if Abfrage

  1. #1
    cont77
    Gast

    Standard if Abfrage

    Hallo,

    ich bin gerade total ratlos und stehe voll auf dem Schlauch.

    Ich will Katalog-Felder nur ausgeben wenn auch ein Wert eingetragen wurde.

    Wenn ich folgenden Code in der catalog_simple.html5 schreibe

    PHP-Code:
    <?php foreach ($entry['data'] as $field=>$data): ?>
    <div class="field <?php echo $field?>">

    <?php if($entry['data']['name']['value']):?>
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;"><?php echo $entry['data']['name']['value']; ?></h2>
      </div>
      
    <?php elseif($entry['data']['emailadresse']['value']):?>
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;"><?php echo $entry['data']['emailadresse']['value']; ?></h2>
      </div>  

    <?php endif; ?>
    </div>
    <?php endforeach; ?>
    ... passiert aber etwas für mich ganz seltsames:

    Der Name wird jeweils 2x ausgegeben. Die Emailadresse überhaupt nicht.

    Code:
    Array
    (
        [0] => Array
            (
                [id] => 9
                [catalog_name] => Mitglieder Tipps
                [parentJumpTo] => 0
                [tablename] => mitglieder_tipps
                [showLink] => 
                [class] =>  first even
                [link] => <a href="teammitglieder-leser/items/9.html" title="Details">Details</a>
                [url] => teammitglieder-leser/items/9.html
                [data] => Array
                    (
                        [name] => Array
                            (
                                [label] => Tipp
                                [type] => text
                                [raw] => test1
                                [value] => test1
                                [items] => Array
                                    (
                                        [0] => test1
                                    )
    
                                [values] => Array
                                    (
                                        [0] => test1
                                    )
    
                            )
    
                        [emailadresse] => Array
                            (
                                [label] => Emailadresse
                                [type] => text
                                [raw] => info@test1.de
                                [value] => info@test1.de
                                [items] => Array
                                    (
                                        [0] => info@test1.de
                                    )
    
                                [values] => Array
                                    (
                                        [0] => info@test1.de
                                    )
    
                            )
    
                    )
    
            )
    
        [1] => Array
            (
                [id] => 15
                [catalog_name] => Mitglieder Tipps
                [parentJumpTo] => 0
                [tablename] => mitglieder_tipps
                [showLink] => 
                [class] =>  last odd
                [link] => <a href="teammitglieder-leser/items/15.html" title="Details">Details</a>
                [url] => teammitglieder-leser/items/15.html
                [data] => Array
                    (
                        [name] => Array
                            (
                                [label] => Tipp
                                [type] => text
                                [raw] => Test Tipp
                                [value] => Test Tipp
                                [items] => Array
                                    (
                                        [0] => Test Tipp
                                    )
    
                                [values] => Array
                                    (
                                        [0] => Test Tipp
                                    )
    
                            )
    
                        [emailadresse] => Array
                            (
                                [label] => Emailadresse
                                [type] => text
                                [raw] => 
                                [value] => 
                                [items] => Array
                                    (
                                    )
    
                                [values] => Array
                                    (
                                    )
    
                            )
    
                    )
    
            )
    
    )
    ergibt:

    HTML-Code:
    <div class="item  first even">
    
    
    <div class="field name">
    
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;">test1</h2>
      </div>
      
    </div>
    <div class="field emailadresse">
    
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;">test1</h2>
      </div>
      
    </div>
    
    
    </div>
    
    <hr/>
    <hr/>
    
    <div class="item  last odd">
    
    
    <div class="field name">
    
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;">Test Tipp</h2>
      </div>
      
    </div>
    <div class="field emailadresse">
    
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;">Test Tipp</h2>
      </div>
      
    </div>
    
    
    </div>
    Was mache ich falsch??

    Danke & Grüße.

  2. #2
    Maintainer Avatar von xtra
    Registriert seit
    02.07.2009.
    Ort
    Tuebingen
    Beiträge
    2.007
    User beschenken
    Wunschliste

    Standard

    PHP-Code:
    <?php foreach ($entry['data'] as $field=>$data): ?>
    <div class="field <?php echo $field?>">

    <?php if($entry['data']['name']['value']):?>
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;"><?php echo $entry['data']['name']['value']; ?></h2>
      </div>
    <?php endif; ?>

    <?php if($entry['data']['emailadresse']['value']):?>
      <div style="border: 1px solid red; margin-top: 10px;">
      <h2 style="margin: 0.1em 0;"><?php echo $entry['data']['emailadresse']['value']; ?></h2>
      </div>  

    <?php endif; ?>
    </div>
    <?php endforeach; ?>
    Bedenke stets: Wenn Du ungenaue oder unzureichende Angaben machst, so koennte dies die Bearbeitung deiner Frage endlos verzoegern (oder sogar dazu fyhren, dass ich zu viel nachdenken muss und die Antwort vergesse!). Kein Support per PN.

  3. #3
    cont77
    Gast

    Standard

    Hatte ich glaub auch schon probiert.

    Das Ergebnis:

    HTML-Code:
    <section class="mod_cataloglist block">
      <div class="layout_simple">
        <div class="item  first even ce_mitglieder">  
          <div class="field tipp_name">      
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">test1</h2>   
            </div>        
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">info@test1.de</h2>   
            </div>      
          </div>    
          <div class="field tipp_emailadresse">      
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">test1</h2>   
            </div>        
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">info@test1.de</h2>   
            </div>      
          </div>     
        </div>
        <div class="item  last odd ce_mitglieder">  
          <div class="field tipp_name">      
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">Test Tipp</h2>   
            </div>      
          </div>    
          <div class="field tipp_emailadresse">      
            <div style="border: 1px solid red; margin-top: 10px;">    
              <h2 style="margin: 0.1em 0;">Test Tipp</h2>   
            </div>      
          </div>     
        </div>
      </div>  
    </section>
    Alles doppelt

  4. #4
    cont77
    Gast

    Standard

    Bereinigt:

    PHP-Code:
    <?php if (count($this->entries)): ?>

    <div class="layout_simple">

    <?php foreach ($this->entries as $entry): ?>
    <div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''?>">


    <?php foreach ($entry['data'] as $field=>$data): ?> 
    <div class="field <?php echo $field?>"> 

    <?php if($entry['data']['tipp_name']['value']):?> 
      <?php echo $entry['data']['tipp_name']['value']; ?>
    <?php 
    endif; ?> 

    <?php if($entry['data']['tipp_emailadresse']['value']):?> 
      <?php echo $entry['data']['tipp_emailadresse']['value']; ?>   
    <?php endif; ?>
     
    </div> 
    <?php endforeach; ?> 

    <?php if ($entry['showLink'] && $entry['link']): ?>
    <div class="link"><?php echo $entry['link']; ?></div>
    <?php endif; ?>
    <?php 
    if ($entry['linkEdit']): ?>
    <div class="linkEdit"><?php echo $entry['linkEdit']; ?></div>
    <?php endif; ?>
    </div>

    <?php endforeach; ?>
    </div>
     
    <?php else: ?>

    <?php if ($this->condition): ?>
    <div class="condition"><?php echo $this->condition?></div>
    <?php else: ?>
    <p class="info">There are no entries matching your search.</p>
    <?php endif; ?>

    <?php endif; ?>
    ergibt:

    HTML-Code:
    <section class="mod_cataloglist block">
      <div class="layout_simple">
        <div class="item  first even">  
          <div class="field tipp_name">      test1      info@test1.de      
          </div>    
          <div class="field tipp_emailadresse">      test1      info@test1.de      
          </div>    
        </div>
        <div class="item  last odd">  
          <div class="field tipp_name">      Test Tipp    
          </div>    
          <div class="field tipp_emailadresse">      Test Tipp    
          </div>    
        </div>
      </div>  
    </section>

  5. #5
    Maintainer Avatar von xtra
    Registriert seit
    02.07.2009.
    Ort
    Tuebingen
    Beiträge
    2.007
    User beschenken
    Wunschliste

    Standard

    Ach so, jetzt kapier ich erst was du willst... sorry, du hast ja das foreach noch mit drin, dann muss man das so umbauen:
    PHP-Code:
    <?php if (count($this->entries)): ?>

    <div class="layout_simple">

    <?php foreach ($this->entries as $entry): ?>
    <div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''?>">
    <?php foreach ($entry['data'] as $field=>$data): ?> 
    <?php if($data['value']):?>
    <div class="field <?php echo $field?>"> 
      <?php echo $data['value']; ?>
    </div> 
    <?php endif; ?> 
    <?php endforeach; ?> 

    <?php if ($entry['showLink'] && $entry['link']): ?>
    <div class="link"><?php echo $entry['link']; ?></div>
    <?php endif; ?>
    <?php 
    if ($entry['linkEdit']): ?>
    <div class="linkEdit"><?php echo $entry['linkEdit']; ?></div>
    <?php endif; ?>
    </div>

    <?php endforeach; ?>
    </div>
     
    <?php else: ?>

    <?php if ($this->condition): ?>
    <div class="condition"><?php echo $this->condition?></div>
    <?php else: ?>
    <p class="info">There are no entries matching your search.</p>
    <?php endif; ?>

    <?php endif; ?>
    Du hast bei dir oben alle Felder durchlaufen und bei jedem Feld gecheckt, ob email und name gesetzt sind und entsprechend daher alles doppelt ausgegeben.

    Nun checkst du nur noch ob das "aktuelle" Feld einen Wert hat und gibst den entsprechend aus (oder auch nicht).
    Bedenke stets: Wenn Du ungenaue oder unzureichende Angaben machst, so koennte dies die Bearbeitung deiner Frage endlos verzoegern (oder sogar dazu fyhren, dass ich zu viel nachdenken muss und die Antwort vergesse!). Kein Support per PN.

  6. #6
    cont77
    Gast

    Standard

    Also, dass foreach einfach raus, dann klappts. Super!

    Der komplett Code für die Lösung in dem Fall:

    PHP-Code:
    <?php if (count($this->entries)): ?>

    <div class="layout_simple">

    <?php foreach ($this->entries as $entry): ?>
    <div class="item<?php echo $entry['class'] ? ' '.$entry['class'] : ''?>">

    <?php if($entry['data']['tipp_name']['value']):?>
    <div class="field <?php echo $field?>">  
      <?php echo $entry['data']['tipp_name']['value']; ?>
    </div> 
    <?php endif; ?> 

    <?php if($entry['data']['tipp_emailadresse']['value']):?> 
    <div class="field <?php echo $field?>">  
      hallo: <?php echo $entry['data']['tipp_emailadresse']['value']; ?>
    </div>     
    <?php endif; ?>

    <?php if ($entry['showLink'] && $entry['link']): ?>
    <div class="link"><?php echo $entry['link']; ?></div>
    <?php endif; ?>
    <?php 
    if ($entry['linkEdit']): ?>
    <div class="linkEdit"><?php echo $entry['linkEdit']; ?></div>
    <?php endif; ?>
    </div>

    <hr>

    <?php endforeach; ?>
    </div>
     
    <?php else: ?>

    <?php if ($this->condition): ?>
    <div class="condition"><?php echo $this->condition?></div>
    <?php else: ?>
    <p class="info">There are no entries matching your search.</p>
    <?php endif; ?>

    <?php endif; ?>
    Funktioniert! Und ist hoffentlich auch "guter Code".

    Danke an xtra.

Aktive Benutzer

Aktive Benutzer

Aktive Benutzer in diesem Thema: 1 (Registrierte Benutzer: 0, Gäste: 1)

Lesezeichen

Lesezeichen

Berechtigungen

  • Neue Themen erstellen: Nein
  • Themen beantworten: Nein
  • Anhänge hochladen: Nein
  • Beiträge bearbeiten: Nein
  •