Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    There is no automatic delete functionality.

    Thread Starter web256

    (@maustyle)

    Hi Micheal, how would you go to build a query to delete all records with the same username or userID, except for the last one?

    Plugin Author Michael Simpson

    (@msimpson)

    Here is the structure of the table from which you would work out your query: https://cfdbplugin.com/?page_id=71

    Entries submitted using Gravity Forms generates:

    field_name = Submitted Login
    field_order = 9999
    field_value = the user’s login name

    (may vary for other forms, but look at your database to see)

    So prior to submitting your user’s new entry you could do something like

    $current_user = wp_get_current_user()
    DELETE FROM <database.table> WHERE ‘Submitted Login’ = $current_user->user_login

    and THEN enter the new stuff

    That should delete all of the current user’s previous entries and leave only the new entry.

    (untested, no guarantees it’ll actually work as written)

    Good luck.

    Thread Starter web256

    (@maustyle)

    thanks we have achieved it following the suggestion and we came up with this code where client_id is the user ID column of the form.

    require_once(ABSPATH.'wp-includes/pluggable.php');
    
    $current_user = wp_get_current_user();
    $u_ID = $current_user->ID;
    
    $exp->export($atts['{$tableValue}'], array('filter' => "client_id=$u_ID", 'limit' => '1'));
    
    while ($row = $exp->nextRow()) {
        extract($row);
    
    }
    
    echo "sid=".$submit_time;
    
    global $wpdb;
    
    $wpdb->get_results("
    DELETE submits
    FROM <code>cf7dbplugin_submits</code> AS submits
        INNER JOIN (
            SELECT
                  submit_time
                , client_id
            FROM (
                SELECT
                      submit_time
                    , MAX(CASE WHEN field_name = 'client_id' THEN field_value END) AS client_id
                FROM <code>cf7dbplugin_submits</code>
                GROUP BY submit_time
            ) AS submit_pivot, (SELECT @rank := 0) AS variable
            WHERE client_id = '".$u_ID."' AND submit_time <> '".$submit_time."'
            ORDER BY client_id, submit_time DESC
        ) AS old_questions
            ON submits.submit_time = old_questions.submit_time
    ");
Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Always delete all previous submissions and keep just the last one’ is closed to new replies.