php - Retrieve Data from 3 tables and finding intersections -


i retrieve 3 datasets query1:to find new products,query2:products in sale,query3:popular products , need find if products new , in sale , popular or if products new or in sale etc. since limit queries 5 there possibility of not getting same id's @ same time.i added php code logically wrong mentioned.what best of way doing that,i need help.thanks in advance query1:

select p.`productid`,`typeid`,c.companyid cid,c.`name` cn,p.`name`,`picture`,`price`,s.`saleprice`,count(l.productid) likes,'1' popular  `product` p inner join company c on c.companyid=p.companyid inner join likes l on l.productid=p.productid left outer join sale s on s.productid=p.productid l.ts>date_sub(now(), interval 7 day) , c.companyid in(1,2,3) group p.`productid`,`typeid`,c.`name`,p.`name`,`picture`,`price`  order likes desc limit 0,5 

query2:

select p.`productid`,`typeid`,c.companyid cid,c.`name` cn,p.`name`,`picture`,`price`,s.`saleprice`,s.endtime,s.begintime,'1' sale   `product` p inner join company c on c.companyid=p.companyid inner join sale s on s.productid=p.productid left outer join salesizelimit sl on sl.saleid=s.saleid now()>=s.begintime , s.endtime>=now() , c.companyid in(1,2,3)   order s.endtime asc  limit 0,5 

query3:

select p.`productid`,`typeid`,c.companyid cid,c.`name` cn,p.`name`,`picture`,s.`saleprice`,`price`,'1' new    `product` p inner join company c on c.companyid=p.companyid left outer join sale s on s.productid=p.productid p.ts>date_sub(now(), interval 7 day) , c.companyid in(1,2,3) order p.`productid` desc limit 0,5   

php code:

function discriminate($set1,$set2,$set3) { // popular,sale,new      $drt=array();      $drv=0;      if(count($set1)>0){                $drv=1;                $drt=$set1;                if (count($set2)>0){                foreach ($set2 $p2) {                        $interim=0;                        $i=0;                           foreach ($set1 $p1) {                               if($p1->productid==$p2->productid){                                   $drt[$i]->sale=1;                                   $interim=1;                               }                               $i++;                            }                           if($interim==0){                            $drt[]=$p2;                        }                    }                }                  $seti=$drt;                  if (count($set3)>0){                   foreach ($set3 $p3) {                       $interim=0;                       $i=0;                            foreach ($seti $pi) {                              if($pi->productid==$p3->productid){                                  $drt[$i]->new=1;                                  $interim=1;                              }                              $i++;                           }                         if($interim==0){                           $drt[]=$p3;                       }                    }                 }        }      else{ // there no new product in company          if(count($set2)>0){                   $drv=1;                   $drt=$set2;                   if (count($set3)>0){                       foreach ($set3 $p3) {                         $interim=0;                         $i=0;                            foreach ($set2 $p2) {                                if($p2->productid==$p3->productid){                                    $drt[$i]->new=1;                                    $interim=1;                                }                                $i++;                             }                            if($interim==0){                             $drt[]=$p2;                         }                     }                 }          }           else{ // there no sale in company               if(count($set3)>0){                   $drv=1;                   $drt=$set3;                }                 else{ // there no popular product in company                 $drv=0;               }          }      }      if($drv==1){          return $drt;      }      else{          return 0;      }   } // end discrimination 


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -