Welcome Guest, Not a member yet? Register   Sign In
how to fetch sub category name and category name from database using sub category id
#1

[eluser]Unknown[/eluser]
Details


i created 3 tables. category table,sub category table and registration table. cat_name and cat_id are fields of category table. sub_cat_id,sub_cat_name and cat_id are the fields of sub category table. in registration form user will add both subcategory and category from drop down list. when user submit the form, only sub category id inserted into registraion table.

i want to display all users details including subcategory name and category name in to a table. as i allowed only subcategory id insertion into registration table, how i display category name and subcategory name with all other user details in to single table on webpage? please help........
#2

[eluser]bgreene[/eluser]
seems simple or have i not understood the question? fools rush in where angels fear to tread 8=)
select r.*, s.sub_cat_name, c.cat_name from registrations r
where r.id = theusers_id
left join subcats s on s.id = r.subcat_id
left join cats c on c.id = s.cat_id

the left joins are needed in case the user has an invalid subcat_id




Theme © iAndrew 2016 - Forum software by © MyBB