sql >> Databasteknik >  >> RDS >> Mysql

php-kategori, underkategoriträd

$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. Hur kan jag använda mysql i C++?

  2. Hur make_date() fungerar i PostgreSQL

  3. Kryptering i vila och/eller AES_ENCRYPT

  4. MySQL-ranking i fallet med slipsar