Jump to content

Filtering results by a field within a ProFields Table


Reid Bramblett
 Share

Recommended Posts

OK, after three days of banging my head against this, I turn to the forums.

I am attempting to apply what would seem to be a rather straightforward filter to a set of results, but am tripping over... something (suspect it's because I continue to have difficulty wrapping my brain around the operation of the ProFields Table field; also, a bit shaky on PageArrays in general).

I have a links page that includes a "title" field, a "categories" field and a "urls" ProFields Table.

The urls Table has rows/fields for "poiurl" (the actual full url), "urltext" (the link as I want it to appear), "desc" (an optional description field), and "place" (a dropdown select populated by another page).

I can get the appropriate links page (filtered by a previously defined "$pcat" category), grab all the urls from the Table, and display them. However, I cannot figure out how to limit those results by a particular field—in this case, "place," as I want to return only those links that match the current page's "place."

$place=$page->place;
$links = $pages->get("template=links, categories=$pcat");
    echo "<h4>$links->title</h4>
    <ul>";
    foreach ($links->urls as $u) {
      if ($u->desc) echo "<li><a href='$u->poiurl'>$u->urltext</a> ($u->desc)</li>";
      else echo "<li><a href='$u->poiurl'>$u->urltext</a></li>";
    }
    echo "</ul>";

So, how do I get it to show only the $u results wherein $u->place=$place? 

Thanks!

Link to comment
Share on other sites

Maybe like this:

$place=$page->place;
$links = $pages->get("template=links, categories=$pcat");
    echo "<h4>$links->title</h4>
    <ul>";
    $filteredLinks = $links->urls->find('place=$place');
    foreach ($filteredLinks as $u) {
      if ($u->desc) echo "<li><a href='$u->poiurl'>$u->urltext</a> ($u->desc)</li>";
      else echo "<li><a href='$u->poiurl'>$u->urltext</a></li>";
    }
    echo "</ul>";
Link to comment
Share on other sites

Maybe like this:

$place=$page->place;
$links = $pages->get("template=links, categories=$pcat");
    echo "<h4>$links->title</h4>
    <ul>";
    $filteredLinks = $links->urls->find("place=$place");
    foreach ($filteredLinks as $u) {
      if ($u->desc) echo "<li><a href='$u->poiurl'>$u->urltext</a> ($u->desc)</li>";
      else echo "<li><a href='$u->poiurl'>$u->urltext</a></li>";
    }
    echo "</ul>";

Once I replaced the single quotes around place=$place with double quotes, that worked. Thanks!

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

×
×
  • Create New...