PHP NESTED LOOP (WHILE) TO DISPLAY DATA IN CATEGORIES

$query1= "SELECT DISTINCT OMEX_CAT FROM extras";
$result1=mysqli_query($conn, $query1);
while($row1=mysqli_fetch_assoc($result1)){
        $value=$row1['OMEX_CAT'];
        echo  '<h3>'. $value.'</br></h3>';
       
        $query2= "SELECT * FROM extras where OMEX_CAT ='". $value. "'";
        $result2=mysqli_query($conn, $query2);
        while($row2=mysqli_fetch_assoc($result2)){
            $value2=$row2['OMEX_NAME'];
            echo $value2.'</BR>';
        }
echo "</br>";
}


CATEGORY ONE
Item 1
Item 2

CATEGORY TWO
option 1
option 2

Comments

Popular posts from this blog

Real-Time Web Interface to MQTT using Socket.io and Node.js

Insert session variable into MySQL database

Insert CheckBox and Radio button Data in MySQL Database Using PHP