Jump to content

Alphabetically sort an associative database?


Recommended Posts

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.

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}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.