sql >> Database >  >> RDS >> Mysql

php categorie, subcategorie boom

$qry = $conn->prepare('
  SELECT   a.pid, a.parent_name, b.category_name
  FROM     parent_categories a
      JOIN child_categories  b ON a.pid = b.lpid
  ORDER BY a.pid
');

if ($qry->execute()) {
  echo '<ul>';

  $row = $qry->fetch();
  while ($row) {
    $current_pid = $row['pid'];

    echo '<li>', htmlentities($row['parent_name']), '<ul>';
    do {
      echo '<li>', htmlentities($row['category_name']), '</li>';
    } while ($row = $qry->fetch() and $row['pid'] == $current_pid);
    echo '</ul></li>';
  }

  echo '</ul>';
}


  1. implementeer LIKE-query in PDO

  2. Een standaard MySQL/MariaDB-gegevensmap in Linux wijzigen

  3. MySQL Update Kolom van andere kolom in dezelfde tabel

  4. Getallen opmaken met komma's in PostgreSQL