dee19802000 Posted February 16, 2010 Share Posted February 16, 2010 How would i create an sql statement for related items in my database? I have tried this but it isnt dynamic enough because not all sections have education as a related topic SELECT * FROM projects WHERE p_id LIKE '%Education%' Any help would be appreciated. Dee Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/ Share on other sites More sharing options...
Maq Posted February 16, 2010 Share Posted February 16, 2010 You're going to have to elaborate, this doesn't make sense to me. Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013212 Share on other sites More sharing options...
dee19802000 Posted February 16, 2010 Author Share Posted February 16, 2010 Ok, its like projects that are related to another, These should be related by client, category and type of project. So when a user clicks on a project they will see projects that are related by those elements above in a scrolling box. This is my prototype at the minute http://2b.selfip.com/2bv4/project-details.php?cp_id=2&p_id=2 Dee Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013224 Share on other sites More sharing options...
ignace Posted February 16, 2010 Share Posted February 16, 2010 Post your database structure Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013236 Share on other sites More sharing options...
dee19802000 Posted February 16, 2010 Author Share Posted February 16, 2010 see image attached. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013242 Share on other sites More sharing options...
Maq Posted February 16, 2010 Share Posted February 16, 2010 Assuming categories is how you would like to group, you're going to have to join 'projects' and 'project_categories' ON 'cp_id' -> 'c_id'. Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013249 Share on other sites More sharing options...
dee19802000 Posted February 16, 2010 Author Share Posted February 16, 2010 I have that done already, do i need to use a WHERE or LIKE statement to relate them? Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013253 Share on other sites More sharing options...
Maq Posted February 16, 2010 Share Posted February 16, 2010 I have that done already, do i need to use a WHERE or LIKE statement to relate them? For example, if the "Education" category id is 2, you would JOIN the tables like so: SELECT * FROM projects p LEFT JOIN project_categories pc ON p.cp_id = pc.c_id WHERE p.cp_id = 2 Quote Link to comment https://forums.phpfreaks.com/topic/192272-sql-related-projects/#findComment-1013282 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.