• Resolved dacgarz

    (@dacgarz)


    Hi,

    I was wondering if there is a way to retrieve the timestamps on the latest entry by receiver email and subject line. I’m trying show it on the front end where the timestamp would show as the button text after the email is sent. Make sense?

    Basically I’ve using the usually way of retrieving specific variables by SQL SELECT function and it didn’t work on this.
    $lastemailed = $wpdb->get_var($wpdb->prepare(“SELECT timestamp FROM $wpdb->wpml_mails WHERE receiver=%s AND subject=%s”, $useremail, $list_subj));

    The page I need help with: [log in to see the link]

Viewing 2 replies - 1 through 2 (of 2 total)
  • Hi @dacgarz,

    Of course you can query whatever you want on the database table. There is no build in support in my ORM for what you are trying to do so you have to use plain SQL.
    There are issues with your query:
    $lastemailed = $wpdb->get_var($wpdb->prepare("SELECT timestamp FROM $wpdb->wpml_mails WHERE receiver=%s AND subject=%s", $useremail, $list_subj));
    Please enable WP_DEBUG and try to read error messages.

    1. $wpdb->wpml_mails
    $wpdb has no member wpml_mails. Use
    $tablename = $wpdb->prefix . 'wpml_mails';
    instead.
    2. Order by date to get latest
    3. Quote your search strings
    4. Limit is not required by the nature of get_var.

    global $wpdb;
    $tablename = $wpdb->prefix . 'wpml_mails';
    $timestamp = $wpdb->get_var($wpdb->prepare("SELECT timestamp FROM $tablename WHERE receiver=\"%s\" AND subject=\"%s\" ORDER BY timestamp DESC", $useremail, $list_subj));
    submit_button( $text = $timestamp, $type = 'secondary', $name = 'button_latest' );

    Please note that the receiver and subject must match exactly with your current query. You might want to use LIKE.

    • This reply was modified 7 years, 4 months ago by No3x. Reason: typo
    Thread Starter dacgarz

    (@dacgarz)

    Hi No3x,

    Thank you so much for the help. It is working like how I wanted it to. I just had to remove the submit_button() part and made it fit to my current form setup.

    Thanks again.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Access database by SQL quiries’ is closed to new replies.