jonw118 Posted August 31, 2010 Share Posted August 31, 2010 Hi there, I have a site that has several different pages which display products from each category on the designated page. What I am looking to do is create one page that also lists ALL the products. Right now, in the category specific page it has this is in the code: $data = get_portfolio_industry('Building Products'); $offset = $_GET['offset']; if($offset == ''){ $offset = 0; } function get_industries($rec_id){ $sql = "SELECT * FROM `".TBL_PORTFOLIO_INDUSTRY."` WHERE `portfolio_id` = '$rec_id'"; $data = SelectMultiRecords($sql); return $data; } And this is the from the functions file: function get_portfolio_industry($industry){ $sql = "SELECT * FROM `".TBL_PORTFOLIO."` WHERE id IN (SELECT `portfolio_id` FROM `".TBL_PORTFOLIO_INDUSTRY."` WHERE `industry` = '$industry') ORDER BY `id`"; $data=SelectMultiRecords($sql); return $data; } My hope was I would simple combine the products like this: $data = get_portfolio_industry('Building Products,Building Services,General Products'); ...but unfortunately it doesn't combine them. Any thoughts? Any help would be much appreciated. Link to comment https://forums.phpfreaks.com/topic/212215-pulling-multiple-categories-into-one-table-using-get_/ Share on other sites More sharing options...
AbraCadaver Posted August 31, 2010 Share Posted August 31, 2010 The function is only accepting one industry, so do it multiple times and merge them: $data = array_merge( get_portfolio_industry('Building Products'), get_portfolio_industry('Building Services'), get_portfolio_industry('General Products') ); Or you can modify the get_portfolio_industry() to accept multiples. Link to comment https://forums.phpfreaks.com/topic/212215-pulling-multiple-categories-into-one-table-using-get_/#findComment-1105810 Share on other sites More sharing options...
jonw118 Posted August 31, 2010 Author Share Posted August 31, 2010 Awesome!!! Thanks so much for the help. Now, here is a little tricky question since I can now get them all in a table. In the function it calls to order them by ID. Is there anyway it could order them all alpha versus the "ORDER BY 'id'" or is that not possible because of this statement in the function (which is needed for the category specific pages): $sql = "SELECT * FROM `".TBL_PORTFOLIO."` WHERE id IN (SELECT `portfolio_id` FROM `".TBL_PORTFOLIO_INDUSTRY."` WHERE `industry` = '$industry') ORDER BY `id`"; $data=SelectMultiRecords($sql); return $data; } Link to comment https://forums.phpfreaks.com/topic/212215-pulling-multiple-categories-into-one-table-using-get_/#findComment-1105815 Share on other sites More sharing options...
AbraCadaver Posted August 31, 2010 Share Posted August 31, 2010 Quick and dirty function fix: $sql = "SELECT * FROM `".TBL_PORTFOLIO."` WHERE id IN (SELECT `portfolio_id` FROM `".TBL_PORTFOLIO_INDUSTRY."` WHERE `industry` IN ($industry) ) ORDER BY `id`"; $data=SelectMultiRecords($sql); return $data; And call it like this: $data = get_portfolio_industry("'Building Products','Building Services','General Products'"); //or call one like this: $data = get_portfolio_industry("'Building Products'"); There are better ways, but these are easy to understand: Link to comment https://forums.phpfreaks.com/topic/212215-pulling-multiple-categories-into-one-table-using-get_/#findComment-1105816 Share on other sites More sharing options...
AbraCadaver Posted August 31, 2010 Share Posted August 31, 2010 Awesome!!! Thanks so much for the help. Now, here is a little tricky question since I can now get them all in a table. In the function it calls to order them by ID. Is there anyway it could order them all alpha versus the "ORDER BY 'id'" or is that not possible because of this statement in the function (which is needed for the category specific pages): $sql = "SELECT * FROM `".TBL_PORTFOLIO."` WHERE id IN (SELECT `portfolio_id` FROM `".TBL_PORTFOLIO_INDUSTRY."` WHERE `industry` = '$industry') ORDER BY `id`"; $data=SelectMultiRecords($sql); return $data; } Try it. Change ORDER BY `id` to ORDER BY `something_else` Link to comment https://forums.phpfreaks.com/topic/212215-pulling-multiple-categories-into-one-table-using-get_/#findComment-1105822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.