neocorps Posted December 23, 2008 Share Posted December 23, 2008 Hello! Im new in this forum and i hope you can help me with my question. Basically i have 2 tables, one called categories and the other one empresas. categories has ID and Category(category names), empresas has many more but im only interested in ID_CATEGORY(linked id from Categories). What my php does, is that it prints all of the data from empresas, but when i want to sort them by category, it sorts by the ID from Categories, and i need to sort them using the category names. This is the code i have for sorting it. //obtain the sorting order if (isset($_GET['order'])){ $order = $_GET['order']; }else{ $order = "name"; } $query = "SELECT * FROM empresas ORDER BY $order LIMIT $offset, $rowsPerPage"; nevermind the $offset, and $rowsPerPage, its just for paging. So can you help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/138254-sorting-by-values-from-linked-table/ Share on other sites More sharing options...
rhodesa Posted December 24, 2008 Share Posted December 24, 2008 First of all, if you are using LIMIT, you must be using MySQL...not MSSQL. So, can a mod please move this? To answer your question, you need to join the tables: SELECT * FROM empresas e LEFT JOIN categories c ON e.id_category = c.id ORDER BY c.category Quote Link to comment https://forums.phpfreaks.com/topic/138254-sorting-by-values-from-linked-table/#findComment-723142 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.