Support » Plugins » cformsII php mysql help!

  • Resolved nihil.core


    Hello everyone,
    i’m not a database hard coder, but i love wordpress so i’d like to know more.

    i’m using wordpress + cformsII for a school website.
    i have a form for each lesson, so students can subscribe to single lessons, and i have to manage a maximum number of students registrations, different for each lesson.
    so in the plug-in backend i’ve set a maximum number of submission different for each form resulting in a “Registrations are closed” sentence after the number of submission is reached.

    but now i’d love to have a counter for the number of seats left, such as “There are 2 more seats left, hurry up!”
    i didn’t find an automatic way to do this so i’m trying to do a query directly on the database and having a numerical result to show on the page.

    i’ve found that the number of submissions is stored in the new table wp_cformssubmission under form_id
    and the maximum number of submission set is stored in the table wp_cformsdata under field_val where field_name is “Set the maximum number of students” and sub_id is the number of the lesson.

    so now, math should be simple: (maximum number students) – (registrations) = (number of seats left)
    but my poor knowledge of MySQL won’t help me in getting the query works…
    i tried different ways starting from here but i’m stuck.

    any help?
    thank you in advance.


Viewing 5 replies - 1 through 5 (of 5 total)
  • in the end i did it myself!
    i’ll post the code just in case it can be helpful for someone else:

    if ( is_single('240')) {
    $max = $wpdb->get_var( "SELECT field_val FROM $wpdb->cformsdata WHERE field_name = 'Indica un numero massimo di studenti' AND sub_id = '12' " );
    echo '<span style="float:left;">Maximum number of submissions:<b> ' . $max . '</b></span>';
    $registrations = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->cformssubmissions WHERE form_id = '3' " );
    $seats = $max - $registrations;
    echo '<br><span style="float:left;">Seats left:<b> ' . $seats . '</b></span>';
    } ?>

    is_single(‘240’) is the ID of the post
    ‘Indica un numero massimo di studenti’ (in english = Set the maximum number of students) is the field name of the field in the form that the teachers use to propose lessons to select how many students can register to the lesson
    sub_id = ’12’ is the ID where the data of the “teacher’s form” has been stored in the DB (to find this number you have to enter your phpmyadmin, go to the ‘wp_cformsdata’ table and then print or export your ‘sub_id’ – DO THIS ONLY IF YOU KNOW WHAT YOU’RE DOING!)
    form_id = ‘3’ is the ID of the form that the students are using to register to the lesson (you can find this one by entering your phpmyadmin, going to the ‘wp_cformssubmissions’ table and then to form_id – DO THIS ONLY IF YOU KNOW WHAT YOU’RE DOING!)
    › in the end there is the easy math and the printing of the value of the variable!

    i’ve put everything into an if construct because i have a different form for each post, so in my case i’ve had to duplicate the code for each post ID with different values of tables’ ID.
    this code is in the single.php file.

    i know it’s not very automatic but i need it to work in a very short time and i will try to improve it later. For the moment it works!
    You can watch it here

    Hi nihil.core,

    I need to do the exact same thing now on one of my sites. I’m stuck at the point where I need to export/print the sub_id.
    Could you explain how that actually works. I think I can manage the rest alone.

    Thank you for finding a solution to this an sharing it.


    Nobody her anymore!? 🙁

    hi mediatory,

    sorry my late reply…
    i’m confident you solved the problem on your own, anyway to answer your question you just have to dump the ‘wp_cformsdata’ table and then look at the sub_id value of the form you are interested to get the value from.

    if your DB runs on phpmyadmin you can find an “Export” icon in the menu on top!
    i hope this could help 🙂


    Hi nihil.core,

    thanks for the reply. I’m closer now but it still doesn’t work. But I have someone that is helping me with this so I don’t need to bother you anymore :-).


Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘cformsII php mysql help!’ is closed to new replies.