Support » Plugin: Insert PHP Code Snippet » Correct query not parsing / displaying ?

  • Resolved matheus

    (@kakashimateo)


    Hello. I have trouble with placing following PHP. Query works perfect in myPhpAdmin. I would be very appreciative for help 🙂

    
    <?php
    global $wpdb;
    $current_user = wp_get_current_user();
    //
    $my_user = $current_user->user_email;
    
    $result = $wpdb->get_results("
    SELECT DISTINCT Numer AS 'Numer um' FROM (
    SELECT data_id,
    	 MAX( CASE WHEN name = 'submit_time' THEN value END) AS Czas, 
         MAX( CASE WHEN name = 'LoggedUser' THEN value END) AS Adres, 
         MAX( CASE WHEN name =  'numer_um' THEN value END) AS Numer
    FROM wp_cf7_vdata_entry where cf7_id = 330
    GROUP BY data_id DESC
    ) AS EXM
    
    ");
    foreach($result as $row) {
       echo '<p>'.$row->value.'</p>';
    }
    ?>
    //WHERE Adres = "example@example.com"
    
    • This topic was modified 5 years, 9 months ago by Jan Dembowski.
Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author f1logic

    (@f1logic)

    sorry, i cant be of much help here as it is related to your application.
    maybe you can check the count of results or $wpdb->last_error

    Thread Starter matheus

    (@kakashimateo)

    Thing got much more complicated, but I could successfully obtain the data. Thank you for advice!

    I am sharing below in case somebody searches in future:

    
    <?php
    global $wpdb;
    
    $result = $wpdb->get_results("
    SELECT DISTINCT Numer FROM (
    
    SELECT data_id,
    	 MAX( CASE WHEN name = 'submit_time' THEN value END) AS Time, 
         MAX( CASE WHEN name = 'LoggedUser' THEN value END) AS Address, 
         MAX( CASE WHEN name =  'numer' THEN value END) AS Number
    FROM wp_cf7_vdata_entry where cf7_id = 11
    GROUP BY data_id DESC
    ) AS EXM
    WHERE Adres = 'YOURADDRESS@DOT.COM'
    ");
    foreach($result as $row) {
       echo ''.$row->Numer.'<br/>';
    }
    ?>
    
    Thread Starter matheus

    (@kakashimateo)

    Could you please erase code from my first post? Thank you.

    Plugin Author f1logic

    (@f1logic)

    any moderators please remove the code or email from the first post

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    *Reads. Renoves modlook tag*

    I’ve modified the email to example@example.com.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Correct query not parsing / displaying ?’ is closed to new replies.