How do i handle this dividing modulus error?

speedy

I have a function that generates a category menu. What i'm trying to do is to group two category in one ul. The problem is almos fixed but i'm getting an empty ul ( see the pic). How can I fix this ? enter image description here

 function categorie($tab){
    global $mysql;
    $return = "";
    $categorie = $mysql->select(sprintf("SELECT * FROM categorii WHERE tab = '%d'", $tab));

    if($mysql->countRows() > 0){
        $i = 0;
            $return .= "<ul class=\"group\">\n";
                foreach ($categorie as $cat) {
                    if($i % 2 == 0){
                        $return .= "</ul><ul class=\"group\">";
                    }

                    $return .= "\t<li>\n";
                    $return .= "\t\t<ul>\n";
                    $return .= "\t\t\t<li class=\"head-list\">".$cat['categorie']."</li>\n";
                    $return .= $this->subcategorie($cat['categorie']);
                    $return .= "\t\t</ul>\n";
                    $return .= "\t</li>\n";
                    $i++;
                }
                $return .= "</ul>";

    }
    return $return;

}
Bogdan Burym

Try this:

function categorie($tab){
    global $mysql;
    $return = "";
    $categorie = $mysql->select(sprintf("SELECT * FROM categorii WHERE tab = '%d'", $tab));

    if($mysql->countRows() > 0){
        $i = 0;
            $return .= "<ul class=\"group\">\n";
                foreach ($categorie as $cat) {
                    if($i % 2 == 0 && !empty($i)){
                        $return .= "</ul><ul class=\"group\">";
                    }

                    $return .= "\t<li>\n";
                    $return .= "\t\t<ul>\n";
                    $return .= "\t\t\t<li class=\"head-list\">".$cat['categorie']."</li>\n";
                    $return .= $this->subcategorie($cat['categorie']);
                    $return .= "\t\t</ul>\n";
                    $return .= "\t</li>\n";
                    $i++;
                }
                $return .= "</ul>";

    }
    return $return;

}

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I use modulus for float/double?

How do i handle error properly in Laravel?

How do I handle this Git error?

How can I do handle a error in a error handling code?

How do I implement a modulus operator for double variables using frexp?

How do I exit BASH while loop using modulus operator?

How do i handle the null pointer exception error in the below udf

How do I handle if the api error message is undefined?

How do I handle server side rendering error in Nextjs?

golang :how do I handle index out of range error?

How do I handle errors that are already handled by another error?

How do I throw an error in a component and handle it in ErrorHandler?

How do I handle an error and then immediately break out of a promise chain?

How do I solve/handle an occasional API 400 error

How do I handle an error ''list index out of range" as an exception?

How do I handle a 500 error with JSON javascript post?

Netlogo How can I avoid the "dividing by 0" error during the dividing process compiling with Behavior space?

How does the modulus operator handle strings in Javascript

How do I change the color of the pane dividing lines in tmux?

How do I get a integer to keep dividing itself?

How do I nest an array of items dividing them by their first value?

How to do BigDecimal modulus comparison

How do I handle exceptions?

How do I handle this FileNotFoundException?

Kotlin: How do i check if a number has decimal points (modulus solution doesn't work)

How do I construct a public key from a modulus and exponent given as a hex-encoded string?

How to avoid modulus floating point error?

How do I catch exceptions in JwtAuthFilter and handle with Global Error Handler in Spring Boot?

How do I handle error message thrown from SQL to controller.cs