K_N Posted December 10, 2010 Share Posted December 10, 2010 I've got two seperate tables set up, one containing information about an item, e.g. titles, description, stats. The other just containing 3 fields, an entry id, an item id, and the id of a register user that has added that item. I want to be able to pull a user's entries like I am currently doing with: SELECT * FROM `list` WHERE userid = '" .$id. "' ORDER BY id DESC , but sort it by the titles in the information database alphabetically. Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/ Share on other sites More sharing options...
Adam Posted December 10, 2010 Share Posted December 10, 2010 You can use a JOIN to 'join' the two tables. I had to guess some of the table names/columns, but you should be able to work it out: select i.id , i.title , i.description , p.entry_id from items i join possessions p on (i.id = p.item_id) where p.user_id = {$id} Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/#findComment-1145400 Share on other sites More sharing options...
K_N Posted December 11, 2010 Author Share Posted December 11, 2010 Nevermind, I am an idiot. :| Thank you for your help, it worked perfectly once I realized my typo. Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/#findComment-1145852 Share on other sites More sharing options...
K_N Posted December 11, 2010 Author Share Posted December 11, 2010 Now what should I do if both tables have a column called "id" and I need to reference i.id rather than p.id? (When I use $array['id'] I get the contents of p.id, and I get nothing from $array['i.id']) Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/#findComment-1145856 Share on other sites More sharing options...
fenway Posted December 11, 2010 Share Posted December 11, 2010 The table prefixes are not included -- use an explicit column alias. Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/#findComment-1145897 Share on other sites More sharing options...
K_N Posted December 11, 2010 Author Share Posted December 11, 2010 Thanks! Though I realized that data was also stored in the associate table, so I didn't even need it. /facepalm Quote Link to comment https://forums.phpfreaks.com/topic/221225-alphabetically-sort-an-associative-database/#findComment-1145904 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.