Decko
Decko

Reputation: 19385

Referencing a result from an SQL query

I have a web page that shows entries in an sqlite database. To make it more readable I added a feature so allowing a user to group entries together using the group_concat and GROUP BY features.

Before each entry would have a link you could click to get all details of that specific entry. This link would contain the ID of the entry in the database. However now that many entries can be grouped together, I am faced with the problem of getting a link to this group of entries. One way would be to simply include all the IDs of entries that match the specific grouping a user chose, however since each group could contain hundreds of entries, this URL would become very long.

I would think this is a problem many people have faced before so is there a good way to solve the problem of referencing many rows in a table without needing all the individual IDs?

Upvotes: 0

Views: 31

Answers (1)

taro
taro

Reputation: 5832

You could split this into parts:

  • groups listing using group_by clause;
  • single group listing entries filtered using condition passed from previous view;
  • single entry view if needed.

For instance, we have students relation with attributes id, first_name, last_name, grade.

For a first view you're passing group_by parameter with group_by=grade|first_name|last_name. For a second view you're passing parameters attribute from previous grouping page and interested value. So your query will look like this: SELECT * FROM students WHERE attribute=value.

For more complicated grouping you usually save conditions in some temporary storage and passing condition id instead of condition itself.

Upvotes: 1

Related Questions