sql >> Database teknologi >  >> RDS >> Mysql

PHP/MySQL-forespørgselsresultater

prøv sådan noget

// note we need to order by maincategory for this to work
//
$query = "SELECT DISTINCT a.categoryname AS maincategory, b.categoryname AS   
smallcategory FROM wscategories a, wssubcategories b WHERE a.SECTION = 'girls' AND  
b.parentcategory = a.id
ORDER BY maincategory ASC,
smallcategory ASC
";
      $result = mysql_query($query) or die(mysql_error());


      // keep track of previous maincategory
      $previous_maincategory = NULL;

      while ($row = mysql_fetch_assoc($result))
      {

        // if maincategory has changed from previouscategory then display it
        if ($previous_maincategory != $row['maincategory']) {
            echo $row['maincategory'];
        }

        echo "<br/>";
        echo $row['smallcategory'];
        echo "<br/>";

        // record what the previous category was
        $previous_maincategory = $row['maincategory'];
      }


  1. Postgres:Samtidige forespørgsler i en forbindelse

  2. Ekskluder linjeresultater, der har NULL-værdi i et hvilket som helst felt?

  3. SQL resultattabel, match i anden tabel SET type

  4. Hekaton med et twist:In-memory TVPs – Del 2