I would do the following:
SELECT t1.features, t2.name, t2.size, t2.price
FROM table_2 as t2 LEFT JOIN table_1 as t1 ON t2.product_id = t1.product_id

Then in (psuedo) PHP:
$prev_features = "";
 foreach($result as $row){
  if ($row['features'] != $prev_features) {
echo ''Product features: " . $row[''features'] ;
$prev_features = $row['features'];
}
echo $row info...
}


DH


On Thu, Feb 12, 2009 at 10:43 AM, Jose Julian Buda <
jb...@noticiasargentinas.com> wrote:

> table_1:
> product_id      features  .....
> 1                        aaa
> 2                        bbb
> 3                        ccc
>
> table_2 :
> product_id    name   size    price
> 1                     11        1          111
> 1                     12       2         221
> 1                     13        3         331
> 2                      21       1         112
> 2                      22       2        222
> 3                      31      1        113
> 3                      32       2        223
> 3                      33      3        333
>
>
> What i want is the next report for example the size =2
> .............
> Report of products with size =2
>
> Product features : aaa
> Name   12    Price 221
>
> Product features : bbb
> Name 22     Price  222
>
> Product features : ccc
> Name 32     Price  223
> ...........
>
>
> basically what i do now with php is :
> ...
> $cliente=mysql_query("select * from table_1");
> while($row = mysql_fetch_array($cliente))
> {
>    printf("\nProduct features  : %s\n",$row[features]);
>    $cliente2=mysql_query("select name,price from table_2 where
> product_id='$row[product_id]' and size=2");
>    while($row2 = mysql_fetch_array($cliente2))
>    {
>  .     print("Name %s --- Price %s\n",$row2[name],$row2[price],);
>    }
> }
> .........
>
> How can i do this without 2 select and whitout 2 while and the "features"
> be printed just one time?
>
>
> Thank you in advance
>
> Jose Julian Buda

Reply via email to