Support » Plugin: Participants Database » Need Help With Custom List Output – Almost There, But I'm Stuck

  • Resolved harleyquinn


    I created a custom template to output the list so that it looks something like this:

    City, State Zip

    I don’t know if the php coding I used is the best or most efficient solution, but it does what I want except I can’t figure out how to join the City, State and Zip fields to all be on the same line. Right now, all I can get it to do is spit out each field on it’s own separate line.

    Here is the code I have so far, which doesn’t include the state or zip fields:

    <?php if($this->field->name === 'business') : ?>
    <p class="bus">
    <?php $this->field->print_value() ?>
    <?php elseif($this->field->name === 'address') : ?>
    <p class="add">
    <?php $this->field->print_value() ?>
    <?php elseif ($this->field->name === 'city') : ?>
    <p class="city">
    <?php $this->field->print_value('city') ?>
    <?php elseif ($this->field->name === 'phone') : ?>
    <p class="pho">
    <?php $this->field->print_value() ?>

    I have been trying to figure this out on my own now for hours, but my php knowledge is very basic and I am not having any luck. How do I join the City, State and Zip fields so that they are all on one line?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author xnau webdesign


    Easiest way to do this is to build up the value then display it once all the pieces are in…

    <?php elseif ($this->field->name === 'city') :
    $location = $this->field->value;
    elseif ($this->field->name === 'state') :
    $location .= ', ' . $this->field->value;
    elseif ($this->field->name === 'zip') :
    $location .= ' ' . $this->field->value;
    <p class="location">
    <?php echo $location ?>

    See, the $location variable collects all the values then shows them once the last value is added. Of course, you have to make sure those values are listed in that order. There are more robust ways to do this, but I did it this way to kept things compatible with your code.

    That worked! Thanks.

    You mentioned that “there are more robust ways to do this,” can you point me in the direction of what that would be? I know the solution I came up with is not the most elegant, but if there is a better way to get the output I need, I’m definitely open to any suggestions.

    Plugin Author xnau webdesign


    Well, the lovely thing about coding is there’s usually many ways to get something done, so what’s important is that it works and you understand it. The code is working, so the only reason to change it is to learn better coding habits…robustness means that the code is hard to break. The code I gave you can be broken, for instance, if the order of the fields gets changed. So that leads to a process of finding another way to get the job done that doesn’t have that vulnerability.

    For me that would be mandatory because I’m writing code that lots of people will use…it would be less critical if you knew no one was going to mess with things.

    That make total sense and I can see where in your case as a plugin developer that writing code that won’t break is a must. Thanks again for your help.

    I would like to use a custom list as described here. Is this the way that I should do it? Or has anything changed in the past eight months that would be easier? Built into the plugin template maybe?

    Plugin Author xnau webdesign


    Yes… I suggest you take a look at this article: Using the PDb_Template class in your custom templates

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Need Help With Custom List Output – Almost There, But I'm Stuck’ is closed to new replies.