Just wanted to ask if there is an other way of PHP coding for displaying my subcategories and subsubcategries than mine.My tables:Categories-------------------------cat_ID | cat_name------------------4      | Baby & Kids5      | Bicycles6      | Boats7      | Books & Comics....13     | Clothes & Accessories....35     | Sport & Fitness36     | Study....38     | Toys & Games....Subcategories-------------------------subcat_ID | cat_ID | extra_cat_ID | subcat_name------------------------------------------------....15        | 4      | 13           | Baby clothes16        | 4      | 0            | Baby products17        | 4      | 13           | Kids clothes18        | 4      | 38           | Toys19        | 5      | 0            | Bycicles20        | 5      | 0            | Bycicle gear & Accessories21        | 6      | 0            | Boat parts22        | 6      | 0            | Other Boats23        | 6      | 0            | Power Boats24        | 6      | 0            | Sailboats25        | 6      | 35           | Windsurf & Surfing26        | 7      | 0            | Antiquarian27        | 7      | 0            | Books28        | 7      | 38           | Childrens books29        | 7      | 0            | Comics30        | 7      | 0            | Magazines & Newspapers31        | 7      | 36           | Study & TrainingSubsubcategories-------------------------subsubcat_ID | subcat_ID | subsubcat_name-----------------------------------------...470          | 15        | Baptism outfits471          | 15        | Bibs472          | 15        | Body warmers473          | 15        | Bodysuits....496          | 16        | Baby bath497          | 16        | Baby books498          | 16        | Baby inserts499          | 16        | Baby monitors....548          | 17        | Belts549          | 17        | Blouses & Shirts550          | 17        | Body warmer551          | 17        | Boots........740          | 26        | Music741          | 26        | Navy742          | 26        | Novel743          | 26        | Photography........867          | 30        | Animals868          | 30        | Arts and Culture869          | 30        | Branch870          | 30        | Cars870          | 30        | Computers........etc.I know it's just super basic HTML, but what I want to do is this:subcat_name 1subsubcatname 1subsubcatname 2subsubcatname 3subsubcatname 4subsubcatname 5subsubcatname 6subsubcatname 7subcat_name 2subsubcatname 8subsubcatname 9subsubcatname 10subsubcatname 11subsubcatname 12subcat_name 3subsubcatname 13subsubcatname 14subsubcatname 15subsubcatname 16subsubcatname 17subsubcatname 18etc ...My code I use right now:$result=mysqli_query($connect,SELECT subcategories.subcat_name, subsubcategories.subsubcat_name, subcategories.subcat_ID FROM subcategories INNER JOIN subsubcategories ON subcategories.subcat_ID=subsubcategories.subcat_ID WHERE subcategories.cat_ID = $cat_ID OR subcategories.extra_cat_ID = $cat_ID ORDER BY subcategories.subcat_name, subsubcategories.subsubcat_name ASC);$lastcat = 0;while ($row = mysqli_fetch_array($result)){    if($lastcat != $row['subcat_ID']){        $lastcat = $row['subcat_ID'];        echo <br>;         echo $row['subcat_name'];        echo <br>;        echo <br>;        }    echo $row['subsubcat_name'];    echo <br>;    }My code is working fine but what I want to know is if there is a better or safer way of handling it in PHP? Or am I doing it the right way?
Displaying categories and subcategories in php having different tables
php
Yes, let's see:You are vulnerable to SQL injection: By including variables directly in the query, you are making yourself vulnerable to SQL injection attacks. Use prepared statements. Further reading: How can I prevent SQL Injection in PHP?Don't use <br> for vertical spacing control. You should use proper semantic elements, for example:<ul>    <li>Subcat 1        <ul>            <li>Subsubcat 1</li>            <li>Subsubcat 2</li>            <li>Subsubcat 3</li>        </ul>    </li></ul>Aside from that, LGTM. Good job! :)Example for prepared statements:$stmt = mysqli_prepare($connect, SELECT subcategories.subcat_name, subsubcategories.subsubcat_name, subcategories.subcat_ID FROM subcategories INNER JOIN subsubcategories ON subcategories.subcat_ID=subsubcategories.subcat_ID WHERE subcategories.cat_ID = ? OR subcategories.extra_cat_ID = ? ORDER BY subcategories.subcat_name, subsubcategories.subsubcat_name ASC);mysqli_stmt_bind_param($stmt, ii, $cat_ID, $cat_ID);mysqli_stmt_execute($stmt);