Jump to content

How to ount items


Frank Schneider
 Share

Recommended Posts

I have a page member, and i want count a field wich have same entry.

/* Kategorie */
$siteconfig["kategorie"] = array();
$siteconfig["kategorie"][] = "Mitglied";
$siteconfig["kategorie"][] = "Probetraining";
$siteconfig["kategorie"][] = "Zehnerkarte";
$siteconfig["kategorie"][] = "Ehemaliges Mitglied";
$siteconfig["kategorie"][] = "Personal";
$siteconfig["kategorie"][] = "Abo";
$siteconfig["kategorie"][] = "Neuanmeldung";
sort($siteconfig["kategorie"]);

I want count member who has Zehnerkarte, i do as folow but get all member

//=========================================================================================
//
//=========================================================================================
function get_zehner($page)
{
$selector = "template=mitglied,mitglied_kategorie==Zehnerkarte";
 
$ret=$page->count($selector);
 
return($ret);
}

How i can filter to "Zehnerkarte"

 

 

Link to comment
Share on other sites

 
/* Kategorie */
$siteconfig["kategorie"] = array();
$siteconfig["kategorie"][] = "Mitglied";
$siteconfig["kategorie"][] = "Probetraining";
$siteconfig["kategorie"][] = "Zehnerkarte";
$siteconfig["kategorie"][] = "Ehemaliges Mitglied";
$siteconfig["kategorie"][] = "Personal";
$siteconfig["kategorie"][] = "Abo";
$siteconfig["kategorie"][] = "Neuanmeldung";
sort($siteconfig["kategorie"]);
 
 
<!-- Kategorie -->
<div class="col-lg-2">
<div class="form-group">
   <label class="form-control-label">Kategorie: </label>
   <select class="form-control " name="Kategorie" data-placeholder="Kategorie wählen" >
    <?php
          
    foreach ($siteconfig["kategorie"] as $kategorie)
      {
      if ($mitglied->mitglied_kategorie == $form_fields['kategorie']['value'])
        {
        echo "<option value='".$kategorie."' selected='selected'>".$kategorie."</option>\n";
}
else {echo "<option value='".$kategorie."'>".$kategorie."</option>\n";}
 
}
      ?>
      </select>
    </div>
</div>
 
//Save
$mitglied->mitglied_kategorie = $_POST['Kategorie'];
 
//Filter return count the kategorie
<?php
//=========================================================================================
//
//=========================================================================================
function get_zehner($page)
{
$selector = "template=mitglied,mitglied_kategorie=Zehnerkarte";
 
$ret=$page->count($selector);
 
return($ret);
}
 
//=========================================================================================
//
//=========================================================================================
function get_member($page)
{
$selector = "template=mitglied,mitglied_kategorie=Mitglied";
 
$ret=$page->count($selector);
 
return($ret);
}
 
 
 
 
 
 
Link to comment
Share on other sites

Please show how you call get_zehner(). It looks like you’re passing in a Page object $page, but Page has no method count() that takes a selector. You can only call it without any arguments and it will give you the number of children of that page: https://processwire.com/api/ref/page/count/. Perhaps you want to use pages()->count($selector)?

Also, this line is outside of <?php ?> tags and will not be executed: $mitglied->mitglied_kategorie = $_POST['Kategorie'];

Also, please indent and use the forum’s code feature.

  • Like 1
Link to comment
Share on other sites

y not

function get_zehner($page) {
    return wire('pages')->count("parent={$page}, template=mitglied, mitglied_kategorie=Zehnerkarte");
} 

or even

function get_zehner() {
    return wire('pages')->count("parent=/mitglieder/, template=mitglied, mitglied_kategorie=Zehnerkarte");
} 

I would additionally rename the function to something like anzahlZehnerkarte, because I would probably expect "get_zehner" to return a PageArray.

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...