• Eventyret

    (@eventyret)


    Hello and thanks upfront for reading this post.

    My php skills is not the best and been trying to google and everything for the last 3 days, so now i be trying to ask for help here as i did not find anything and maybe the things i found did no be the way i wanted it tobe.

    The site i have will post queries in a database with a form.

    i made a custom “my page” that i want to post statistics from that table.

    So i need to try make a php form / query with the following things.

    table: wp_iphorm_form_entries
    field: value
    has to be LIKE: Certain value
    if posted data is from username
    summery of it in numbers

    So it will show

    | Username | XX |

    This is to be summerized, so if certain value from user a comes up 5 times it should say

    | User A | 5 |

    I really hope on some help here.

    Thank you again.

Viewing 8 replies - 1 through 8 (of 8 total)
  • jholder83864

    (@jholder83864)

    There’s probably an easier way to do this, as there are a ton of experts here.

    I would instantiate a new class for wpdb and use it (calling wp_query(‘SQL HERE’); as the object to reference the contents.

    Then just process the object with PHP. I know this is vauge, but I didn’t really want to write the SQL for you. That’s how you learn, my friend!

    Thread Starter Eventyret

    (@eventyret)

    ^
    Tested something i almost got to work but when did this it does not show anything

    <?php
    $comment_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_iphorm_form_entry_data WHERE  <code>value</code> LIKE  'reg%';"));
    echo '<p>Total comments: ' . $comment_count . '</p>';

    I just used comment_count php i found just to test. This results in nothing.

    jholder83864

    (@jholder83864)

    var_dump $comment_count, let’s see what’s in the object.

    Thread Starter Eventyret

    (@eventyret)

    Yeah got it to work almost now, the last thign i need to get is it from certain user

    <?php
    $fish_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_iphorm_form_entry_data WHERE  <code>value</code>  LIKE 'Registrere fisk';"));
    echo '<p>Total fish: ' . $fish_count . '</p>';
    ?>

    This shows the total count indeed, but i want it to show what “username” only has posted in that field.

    jholder83864

    (@jholder83864)

    You need a where clause for the user.

    where userid = userid

    Thread Starter Eventyret

    (@eventyret)

    But can i use where userid = user_login or something when its not in the same table it gets the info from ?

    Thing is this is from a plugin and shows how many fishes a certain user has catched, but i only want to show how many users THAT person has posted.

    Automaticly the plugin posts the username from{user_login} if that made sense ?

    Thread Starter Eventyret

    (@eventyret)

    I been searching again a bit around and it seems i need to JOIN the tables of some sort, but what i need then is to figure a way out how to post the personal stuff..

    The code

    <?php
    $fish_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_iphorm_form_entry_data WHERE  <code>value</code>  LIKE 'Registrere fisk';"));
    echo '<p>Total fish: ' . $fish_count . '</p>';
    ?>

    Works great for showing everything from that field in the way i want it.
    Now i wanted to try make it personal for the fisher to show more or less

    <?php
    $fish_count = $wpdb->get_var($wpdb->prepare("SELECT COUNT(*) FROM wp_iphorm_form_entry_data WHERE 'value' LIKE 'Registere fisk' FULL OUTER JOIN wp_users ON wp_iphorm_form_entry_data.value = wp_users.userid WHERE 'userid';
    echo '<p>Total fish: ' . $fish_count . '</p>';
    ?>

    Any help on this

    Thread Starter Eventyret

    (@eventyret)

    Tried something new but it seems this gives me an error.

    <?php
    $current_user = wp_get_current_user();
    $brukernavn = $wpdb->get_var(wpdb->prepare(“SELECT FROM wp_iphorm_form_entry_data WHERE ‘brukernavn’ ;”);
    $fish_countp = $wpdb->get_var($wpdb->prepare(“SELECT COUNT(*) FROM wp_iphorm_form_entry_data WHERE value LIKE ‘Registrere fisk’ ;”));
    if ($x==’$current_user’ && $y==’$brukernavn’){
    echo “Brukeren $brukernavn har $fish_countp totalt”
    }else {
    //do otherwise
    }
    ?>

    Any help please ?

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Help with $wpdb’ is closed to new replies.