Okay
  Public Ticket #3079450
PHP Fatal Error: Dividing by Zero
Closed

Comments

  • Alejandro Pinzon started the conversation

    Hi team, 

    I built a page that brings data from my server into a wpdatatable. I then created 3 shortcodes: one to add the number of accounts, another to calculate an average of the ticket amount, and another one to add all transactions. 

    I'm experiencing a PHP fatal error for my website when the source table is empty. I think this is because the system is trying to attempt an average (Division by Zero). 

    Can you please help? These are the logs:

    error 173.0.77.74:0] PHP Fatal error:  Uncaught DivisionByZeroError: Division by zero in /nas/content/live/exampledashprod/wp-content/plugins/wpdatatables/source/class.wpdatatable.php:1560 Stack trace: #0 /nas/content/live/exampledashprod/wp-content/plugins/example-graphql-pull/src/shortcodes/DataTablesAggregate.php(86): WPDataTable->calcColumnFunction('Amount', 'avg') #1 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(356): GraphCMSPull\shortcodes\DataTablesAggregate->output(Array, '', 'example_wpdatatabl...') #2 [internal function]: do_shortcode_tag(Array) #3 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(example_w...', 'do_shortcode_ta...', '

    content(Array, '\n
    loadTemplate(Array, '\n
    output('', '\n
    loadTemplate(Array, '[vc_column_text...') #17 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/classes/shortcodes/core/class-wpbakeryshortcode.php(366): WPBakeryShortCode->content(Array, '[vc_column_text...') #18 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/helpers/helpers.php(1421): WPBakeryShortCode->output(Array, '[vc_column_text...') #19 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(356): vc_do_shortcode(Array, '[vc_column_text...', 'vc_column') #20 [internal function]: do_shortcode_tag(Array) #21 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(example_w...', 'do_shortcode_ta...', '[vc_column colu...') #22 /nas/content/live/exampledashprod/wp-content/plugins/salient-core/includes/vc_templates/vc_row.php(881): do_shortcode('[vc_column colu...') #23 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/classes/shortcodes/core/class-wpbakeryshortcode.php(271): require('/nas/content/li...') #24 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/classes/shortcodes/vc-row.php(40): WPBakeryShortCode->loadTemplate(Array, '[vc_column colu...') #25 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/classes/shortcodes/core/class-wpbakeryshortcode.php(366): WPBakeryShortCode_Vc_Row->content(Array, '[vc_column colu...') #26 /nas/content/live/exampledashprod/wp-content/plugins/js_composer_salient/include/helpers/helpers.php(1421): WPBakeryShortCode->output(Array, '[vc_column colu...') #27 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(356): vc_do_shortcode(Array, '[vc_column colu...', 'vc_row') #28 [internal function]: do_shortcode_tag(Array) #29 /nas/content/live/exampledashprod/wp-includes/shortcodes.php(228): preg_replace_callback('/\\[(\\[?)(wpdata...', 'do_shortcode_ta...', '[vc_row type="i...') #30 /nas/content/live/exampledashprod/wp-includes/class-wp-hook.php(307): do_shortcode('[vc_row type="i...') #31 /nas/content/live/exampledashprod/wp-includes/plugin.php(189): WP_Hook->apply_filters('[vc_row type="i...', Array) #32 /nas/content/live/exampledashprod/wp-includes/post-template.php(253): apply_filters('the_content', '[vc_row type="i...') #33 /nas/content/live/exampledashprod/wp-content/themes/salient/page.php(30): the_content() #34 /nas/content/live/exampledashprod/wp-includes/template-loader.php(106): include('/nas/content/li...') #35 /nas/content/live/exampledashprod/wp-blog-header.php(19): require_once('/nas/content/li...') #36 /nas/content/live/exampledashprod/index.php(17): require('/nas/content/li...') #37 {main}   thrown in /nas/content/live/exampledashprod/wp-content/plugins/wpdatatables/source/class.wpdatatable.php on line 1560, referer: https://portal.example.com/ Wed Jul 06 2022 08:24:24 GMT-0500 (Colombia Standard Time)

  •  2,572
    Aleksandar replied

    Hello Alejandro

    Thank you for reaching out to us.

    When the source table is empty, the calculation functions do try to divide by zero, and that does cause an issue. What's the end result you'd like to see? Exclude empty rows so they're not included in the calculation or simply display some error message?

    Kind Regards, 

    Aleksandar Vuković
    [email protected]

    Rate my support

    wpDataTables: FAQ | Facebook | Twitter | InstagramFront-end and back-end demo | Docs

    Amelia: FAQ | Facebook | Twitter | InstagramAmelia demo sites | Docs | Discord Community

    You can try wpDataTables add-ons before purchasing on these sandbox sites:

    Powerful Filters | Gravity Forms Integration for wpDataTables | Formidable Forms Integration for wpDataTables | Master-Detail Tables