PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE menu (`mid` int, `parent` varchar(4), `org` int, `item` varchar(8), `price` varchar(3)) ; INSERT INTO menu (`mid`, `parent`, `org`, `item`, `price`) VALUES (1, NULL, 1, 'Category', '1'), (2, '1', 1, 'Item 1', '$10'), (3, '1', 1, 'Item 2', '$12'), (4, NULL, 1, 'Category', '2'), (5, '4', 1, 'Item 3', '$12'), (6, '4', 1, 'Item 4', '$90') ;
Copy Clear
Copy Format Clear
<?php $org = "1"; $row1 = mysqli_prepare($mysqli,"SELECT * FROM menu WHERE org = ? ORDER BY mid ASC"); $row1->bind_param("s", $org); mysqli_stmt_execute($row1); $row2 = mysqli_stmt_get_result($row1); $controlfirst = 0; while( $row = mysqli_fetch_array($row2)) { if ( !isset($row["parent"])) { if ( $controlfirst == 1) { ?> </div> <?php } ?> <div class="category"><?php echo $row["item"]; /* GROUPED*/ $controlfirst = 1; } else { ?> <div class="item"><?php echo $row["item"];?> </div>/* INDIVIDUAL ITEM*/ <?php } } if ( $controlfirst == 1) { ?> </div> <?php } ?>
Show:  
Copy Clear