jeudi 9 mai 2019

if Statement not finiding variable when inside function (Wordpress Plugin)

The variable is not accessable inside the funtion. When I echo the variable outside the function I get the correct result. When I echo/use the variable inside the function I get a 'Notice: Undefined variable: crLocalIncompleteStatus in /setup.php on line 35'

Any ideas?

<?php
    global $wpdb;
    $table_name = $wpdb->prefix . 'crLocal';

    $crLocalIncompleteStatus = '';
    $crLocalCompleteStatus = '';

    $crLocal_DBChecked = $wpdb->get_var("SELECT COUNT(*) FROM $table_name");

    function crLocal_CheckDB() {
        global $crLocal_DBChecked,  $crLocalIncompleteStatus, $crLocalCompleteStatus;

        if ($crLocal_DBChecked == '0') { 
            $crLocalIncompleteStatus = 'block' ;
            $crLocalCompleteStatus = 'none' ;
        } elseif ($crLocal_DBChecked != '0') { 
            $crLocalIncompleteStatus = 'none' ;
            $crLocalCompleteStatus = 'block' ;
        } else {
            // Broken
            // More Code to follow
        }

        echo $crLocal_DBChecked;
    }

    crLocal_CheckDB();

    $crLocalInstallIncomplete = '<div id="crLocalInstallIncomplete" style="display: '.$crLocalIncompleteStatus.';">' ;

    $crLocalInstallComplete = '<div id="crLocalInstallComplete" style="display: '.$crLocalCompleteStatus.';">' ;

?>

So I need:

$crLocalIncompleteStatus to be 'block' when the count is 0 from the database and 'none' when its above 0.

$crLocalCompleteStatus to be 'none' when the count is 0 from the database and 'block' when its above 0.

Aucun commentaire:

Enregistrer un commentaire