sql >> Databasteknik >  >> RDS >> Mysql

PHP/MySQL-frågeresultat

prova något sånt här

// 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. Oracle-fråga för att få ett visst datum

  2. Två infogningsfrågor med länkade fält

  3. postgresql nextval genererar befintliga värden

  4. En introduktion till asynkron bearbetning med Service Broker