here i have rc.RelatedCatagory like this (Flex Printing, Offset Printers, Digital Printers, Id Card Printers, Graphic Designers,News Papers)
if i get this ($subcatagory = $_GET['subcatagory'];) from first page value as (Flex Printing), then i want to display only (Flex Printing ) companies. how to match with that value one by one.

3.png is my main table
2.png is my main category

1.png in my frontend design, here i choosed (News Papers) but its showing maincategory wise data. so how can i change this query to subcategory wise.

$maincateg = $_GET['maincateg'];
$maincatid = $_GET['maincatid'];
$subcatagory = $_GET['subcatagory'];
$subcatid = $_GET['subcatid'];

$sql = mysql_query("select DISTINCT s.Companyname,,s.LogoImage,s.LogoPath,s.Url,ck.MainCatagory,,st.state,sub.Subcatagory,sub.MainCatid,p.priority,rc.RelatedCatagory from spa s 
left join relatedcatagories rc on
left join catagorykeywords ck on
left join subcatagorykeywords sub on
left join city_place cp on
left join cities c on c.city_id=cp.city_id 
left join states st on st.state_id=c.state_id
left join priority p on
WHERE s.Publish=1 AND rc.mainCatagoryid='$maincatid' AND ck.MainCatagory='$maincateg' OR rc.RelatedCatagory='$subcatagory' GROUP BY s.Companyname ORDER BY p.priority DESC , DESC LIMIT $start,$limit");

Hmm.. I have no idea what you are trying to accomplish... What do your tables look like? Also, why there are so many left join in your query? If you are seeing this many join, something is wrong with your design... Doing join in query takes a lot of time on the DB part. Do you know how join is done internally? Last but not least, are you sure that your WHERE clause is correct? In other words, the result will be for all of true conditions prior to rc.RelatedCategory='$subcatagory' or only the rc.RelatedCategory='$subcatagory' is true...

commented: this is worth at least 2 upvotes +13
commented: Good ponder! +2

I just read SQL injection all over the shop! You should consider using PDO, or something to just clean that up a little! Also, the mysql_query function or really any mysql_x function are depricated as off PHP5.5, so in essence you ought to use PDO anyway.

this seems to be an insanely complicated database schema
I can't determine

Taywin, sorry mate, I didnt realise you already asked the Q I was going to

need info on DB design