1

I am using a shortcode to generate a unique number for each participant in a query using contact form 7.

My database name is daviddgl_wp1 and the table name is SaveContactForm7_6. The following is the function i have written to count the number of rows in the table. But this is giving the output as 17ICLAA001 all the time whereas in the corresponding table there are more than 2 rows are there.

Is there any problem with this code?

Kindly provide a suggestion to improve this code.

function row_count_shortcode() {
global $wpdb;
$wpdb->get_var( 'SELECT COUNT(*) FROM daviddgl_wp1.SaveContactForm7_6' )+1;
return "17ICLAA".sprintf('%03d',$wpdb->num_rows);
}
add_shortcode( 'row_count', 'row_count_shortcode' );
1

I found the answer. This works fine.

function row_count_shortcode() {
global $wpdb;
$user_count = $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->daviddgl_wp1.SaveContactForm7_6" )+1;
return "17ICLAA".sprintf('%03d',$user_count);
}
add_shortcode( 'row_count', 'row_count_shortcode' );

Not the answer you're looking for? Browse other questions tagged or ask your own question.