Sort by category header

Topics: Developer Forum, Project Management Forum, User Forum
May 24, 2010 at 8:15 AM

Hi, I have that code, and it works, but I need to divide the articles by category. The result I want is this: Article 1, Article2 ...
while I would:
name category1
article1, Article2

name category2
articolo3
articolo4 ...

How can I fix?

Here's the code:

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A2', 'Modello');
$objPHPExcel->getActiveSheet()->setCellValue('B2', 'Descrizione');
$objPHPExcel->getActiveSheet()->setCellValue('C2', 'Prezzo');
$objPHPExcel->getActiveSheet()->setCellValue('D2', 'Disponibile');					 
//contenuti cella
$cnt=3;

  //seleziono tutte le categorie dove sono presenti i prodotti
  $sql1 = "SELECT distinct * FROM products";
  $r_sql1 = $db->query($sql1);
  while($r_r1 = $db->fetch_array($r_sql1)){
    $mast[] = $r_r1[master_categories_id];
  }
  $master = array_unique($mast);
  
  //cilco le categorie con prodotti
  foreach($master as $m){
 
    //seleziono id e nome categoria per il linguaggio italiano
    $co = mysql_query("SELECT distinct * FROM categories_description WHERE categories_id = $m AND language_id = 2");
while($ro = mysql_fetch_array($co)){
  $c_id = $ro[categories_id];	
}



$query = mysql_query("select p.products_model, SUBSTRING(d.products_name, 1, 100) as description, truncate(floor((p.products_price * 20 / 100 + p.products_price) * 100 + .55) /100, 2) as price, IF(p.products_quantity > 0, 'Disponibile', 'Non Disponibile') as vero, c.categories_name from products as p, products_description as d, categories_description as c where master_categories_id = $c_id AND p.products_id = d.products_id AND d.language_id = 2 AND c.language_id = 2 AND c.categories_id = $c_id");
while($row = mysql_fetch_array($query))
{

$objPHPExcel->setActiveSheetIndex(0);
$objPHPExcel->getActiveSheet()->setCellValue('A1', $row[categories_name]);
$objPHPExcel->getActiveSheet()->setCellValue('A'.$cnt, $row[products_model]);
$objPHPExcel->getActiveSheet()->setCellValue('B'.$cnt, $row[description]);
$objPHPExcel->getActiveSheet()->setCellValue('C'.$cnt, $row[price]);
$objPHPExcel->getActiveSheet()->setCellValue('D'.$cnt, $row[vero]);

$cnt++;
}
}

Sorry for my English

Thanks