Forum

Thread tagged as: Members

How do I show member details to the public

I need to show certain member details to the public. Basically, I want the public to filter the members by County then Town and then be show a list of member names and website addresses (all data stored in the member table).

I don't think this is something that Perch does. However I imagine I can simply query the databse directly, but the data is all stored in memberProperties - how do I access the individual properties (quick php/mysql lesson needed here). Unless there is in fact a way I can do it in Perch?

Lisa Morena

Lisa Morena 1 points

  • 4 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

There's not a way to do it with included functionality, so I think yes, taking that PHP and MySQL lesson would be valuable if that's something you want to do.

OK, I am really struggling with this primarily because the county for the address is all stored in the memberProperties column rather than in it's own column. I can pull data and I can filter data, but I can't do much more.

I want to be able to populate a select box with a list of counties which will then be used to search/filter the table for members in that county. However, since I only want to list counties that actually exist in the member table rather than just all of them (which would end up with lots of annoying 'no matches found' results), I just cannot find a way to do that. I asked on phphelp.com and have been told that keeping so much data in the one column is bad database design and that to do what I want I need the county to be in it's own column. Can this be done? Or do you see another way of doing this?

Drew McLellan

Drew McLellan 2638 points
Perch Support

This isn't something we can offer you support for - it's way outside scope.

Particularly so if you're going to criticise my database design without an understanding of why it's structured that way. It doesn't really make me inclined to offer help beyond what your license provides.

I wasn't criticising it! I love Perch and didn't mean to offend! Merely reporting what I had been told when I went in search of a way about it elsewhere.

It would be super though to see the Membership App expanded to allow details to be shown to the public as this could be used in so many ways! For us the membership area is to create trader accounts that not only allows them to access files to download and order online, but also the public need to be able to find what traders are local to them so that they can contact them and make a purchase, rather than allow the public to buy direct.

To be honest I didn't realise that you couldn't show member details to the public by default with the Members App when I set about it all.

Well if anyone else wonders how to do similar, this is what I have done. I use a search field with jquery autocomplete to prevent misspellings:

$key = $_GET['search'];
$key2 = ucwords($key);

    if (isset($_GET['search'])) {
$con = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sth = $con->prepare('SELECT * FROM perch2_members WHERE memberProperties LIKE :search');
$sth->execute(array(':search' => '%"'.$key.'"%'));
$data = $sth->fetchAll(PDO::FETCH_ASSOC);
if (!empty($data)) {
    echo '<h1>Traders in '.$key2.'</h1>
echo "<ul>";
}
foreach($data as $row) {
$myData = json_decode($row['memberProperties'], true);
   // $myData should now be a PHP array which you can access easily
    extract($myData);

    echo "<li>";
     echo "<p><strong>$first_name $last_name</strong> <br />";
    echo "$city, $county <br />";
    if (isset($facebook)) { echo "<a class='anchor' href='$facebook' target='_blank'>Facebook</a> <br />";}
    if (isset($website)) { echo "<a class='anchor' href='$website' target='_blank'>Website</a>"; }
   echo "</p></li>";
    }
if (!empty($data)) {
       echo "</ul>";
}