|  | Posted by bettina on 11/29/05 19:38 
I have 2 tables (simplified):
 coasters (ID,BREWERY_CODE, etc)
 breweries (BREWERY_CODE, BREWERY)
 
 For each brewery I want to count how many coasters are there in table
 "coasters" (up to here it works fine)  and then I want to show them
 ordered by quantity (that's my problem):
 
 The following is the piece of code.
 ......
 $search_breweries = mysql_query("SELECT BREWERY_CODE, BREWERY FROM
 breweries");
 $i = 0;
 while ($row = mysql_fetch_array($search_breweries, MYSQL_NUM)) {
 $breweries[$i][0] = $row[0];
 $breweries[$i][1] = $row[1];
 $key_brewery = $row[0];
 $count_coasters_brewery = mysql_query("SELECT COUNT(*) FROM coasters
 WHERE BREWERY_CODE = $key_brewery");
 $breweries[$i][2] = mysql_result($count_coasters_brewery,0,0);
 $i = $i + 1;
 }
 
 I suppose I have to assign everything to an array and then sort it, but
 I don't know how.
 
 Any help will be welcomed.
 Bettina
  Navigation: [Reply to this message] |