--- In [email protected], crazy mike <[EMAIL PROTECTED]> wrote: > > I have three tables: > groups, companies and companies_to_groups. > > companies table has all the companies info > groups table has all the groups info > and companies_to_groups has id's of companies together > with id's of groups. There can be many companies in > the same group. > > So what i need is a way to get all the company names > that belong to a specific group id and at the same > time sort them in alphabetic order. I have no idea how > to do that, could someone help me please, i have the > following query, but it doesn't work: > > $sql="SELECT C.name as name, C.id as company_id, K.id > as del_id "; > $sql.="FROM companys as C, companys_to_groups as K"; > $sql.="WHERE C.id=K.company_id AND K.group_id = $curid > order by C.name"; >
In your query there is no space between the "companys_to_groups as K" and "WHERE". If you echo the query it will look like this (SELECT C.name as name, C.id as company_id, K.id as del_id FROM companys as C, companys_to_groups as KWHERE C.id=K.company_id AND K.group_id = $curid order by C.name) give space between K and WHERE(as K WHERE C.id=). > > $sql="SELECT C.name as name, C.id as company_id, K.id > as del_id "; > $sql.="FROM companys as C, companys_to_groups as K "; > $sql.="WHERE C.id=K.company_id AND K.group_id = $curid > order by C.name"; > check the $curid value also. > Could someone help me out please? > > > ______________________________________________________________________ > Post your free ad now! http://personals.yahoo.ca >
