• Resolved benorange

    (@benorange)


    Hi all,

    I am looking for support with how to access two users’ accounts at the same time. Thanks in advance.

    I am referring to: https://wpdataaccess.com/docs/data-projects/user-roles-and-where-clauses/

    Specifically:

    `In a student administration system for example, you might need a page to inform students about their personal results. Suppose student results are stored in table STUDENT_RESULTS which has a column STUDENT_NAME that holds the WordPress username of the student (or STUDENT_ID that holds the WordPress userid of the student).

    To give students access to thier own data only, you can add the following WHERE clause to the student result page:
    STUDENT_NAME = $$USER$$ (or STUDENT_ID = $$USERID$$)

    Students will see their own results only. If you have users who need to see all results, you might need a second student result page available to their role.`

    Imagine 2 siblings attend the same course, we are working towards the parent being able to see both childrens’ uploaded results in one place without having to log in twice to compare the results. This could be through a separate account to the individual students’ accounts.

    Does anyone have advice about how we could use this plugin to allow parents to see data/results from more than one user account at the same time?

    If that question is too broad then simply do you think I could achieve this with data access?

    Bw,
    Ben`

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    Interesting use case! 😊

    Since you only have one user id per user account, I don’t see a way to solve this using a direct query on the WP users table. But you could add your own “family table” to group children. Suppose we call this the family_table, your where clause could like something like:
    STUDENT_ID in (select STUDENT_ID from family_table where PARENT_ID = $$USER$$)

    Of course you need to make sure the data is available in the family table. You could maintain that table for families only (children>1) by adding an extra condition like:
    STUDENT_ID in (select STUDENT_ID from family_table where PARENT_ID = $$USER$$)
    or STUDENT_ID = $$USER$$

    This makes the family_table administration simpler. What do you think? Could this work for you?

    Best regards,
    Peter

    Thread Starter benorange

    (@benorange)

    Hi Peter,

    Thank you for thoughtful reply. I’m making a site clone later next week and I will start trying things out then. Everything up to now has worked out-of-the-box so I’m really studying as I am sure this project will need more than I know, need to make the jump from designer with the odd borrowed snippet to quasi-developer for some new requirements..

    I don’t want to take up your time until I have a better idea of my plan so will follow up properly later but this is what I’m thinking so far, I know this will probably be much more complicated to work..

    So there is a users database and new family database/table, parent ids will be not unique and can be assigned to multiple users. I guess I could use Heidi to create/populate new db and test a demo..

    Then create a family.php file with similar to your query, something like:

    <?php
    	require-once('wp-load.php');
    	$get = $wpdb->get_results(" SELECT * from ".$wpdb->prefix."family_table" where PARENT_ID = 0001 ");
    	echo "<pre>";print_r();echo "</pre>"
    ?>

    Then load URL https://domain.com/family.php

    If that shows the children ids of the test parent, then repeat with showing the results for the children, following the standard model and db link to scores:

    <?php
    // The Query
    $the_query = new WP_Query( $args );
    // The Loop
    if ( $the_query->have_posts() ) {
        echo '<ul>';
        while ( $the_query->have_posts() ) {
            $the_query->the_post();
            echo '<li>' . get_the_title() . '</li>';
        }
        echo '</ul>';
    } else {
        // no posts found
    }
    /* Restore original Post Data */
    wp_reset_postdata();

    Then edit query to use the parent ID for current user $$USER$$.

    Then include your condition:

    STUDENT_ID in (select STUDENT_ID from family_table where PARENT_ID = $$USER$$)
    or STUDENT_ID = $$USER$$

    Then retest for no crash with an only-child user.

    And add a condition for connection failure like:

    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    Then copy php file into a PHP snippet and insert into new family reports page on site.

    I’d be grateful for a ‘you’re on the right track’ or ‘no, no, no’ if you have a minute. Thanks again.

    I’ll follow up soon.

    Bw,
    Ben

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    I can’t tell if you’re on the right track with those posts, but the default where should work. Maybe good to mention that you need an additional table to store the relationship between parents and children.

    In its simplest form you could have a table which contains a parent_id and a student_id and a primary key on both columns. Just enter the parent user_id in combination with the student_id’s for all children and you should be fine.

    Just give it a try. If the default where clause does not work, you just get the wrong answer and you’ll try again an until you get the right answer. 😊

    Best regards,
    Peter

    Thread Starter benorange

    (@benorange)

    Thanks Peter,

    Will do!

    Bw,
    Ben

    Plugin Author Passionate Programmer Peter

    (@peterschulznl)

    Hi Ben,

    Did you make any progress with this issue? Can I close it?

    Thanks,
    Peter

    Thread Starter benorange

    (@benorange)

    Hi @peterschulznl,

    Thanks for follow up and advice. Not resolved but I have half a plan, not enough to be helpful to anyone else yet. Will close ticket though.

    Bw,
    Ben

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Family users’ is closed to new replies.