SyncViews Posted April 15, 2008 Share Posted April 15, 2008 database structure categorys: category_id category_name category_display sections: section_id category_id section_name section_decription section_display The category_id in the sections tabel says what category the section is under. I need to query the database and get these into some arrays but I'm not sure what is the best way. Each "group" needs to be order by the _display valuse in assending order category | |--section -> section data | |--section -> section data category | |--section -> section data So I should have 3 "layers" of arrays eg Eg to get the name of the first section in the first catagory: $data[0][0]["section_name"] I have got it to an extent but it doubles up the category data and I'm not sure it's a particualy fast query either... The other problem is I can't see a good way to seperate the catagorys so I can insert the catagory names in between where as with a big array I could just use a double foreach loop <?php $query = mysql_query(' SELECT category.category_name, sections.sections_name, sections.sections_desc FROM categorys, sections WHERE category.category_id=category.category_id ORDER BY categorys.display, sections.display ') or exit(mysql_error()); ?> Link to comment https://forums.phpfreaks.com/topic/101138-getting-from-sql-database-to-something-i-can-use/ Share on other sites More sharing options...
poleposters Posted April 15, 2008 Share Posted April 15, 2008 WHERE category.category_id=category.category_id WHERE x=x? I think you mean section.sectionid Link to comment https://forums.phpfreaks.com/topic/101138-getting-from-sql-database-to-something-i-can-use/#findComment-517306 Share on other sites More sharing options...
SyncViews Posted April 15, 2008 Author Share Posted April 15, 2008 opps...it's WHERE categorys.category_id=sections.category_id Link to comment https://forums.phpfreaks.com/topic/101138-getting-from-sql-database-to-something-i-can-use/#findComment-517494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.