0

Here is the scenario, I have a database and I need data that is different from four tables to display in a list. I was having trouble getting the queries to join in a way that would give the results that I needed in the right order and format so I did a bunch of queries and pushed the results to and array. So now I have this array and it works great so far.

To visualize this I have the data listed in table and I need to sort the table based on the heading.

What I need to do next is some how sort the array by a specific value.

For example I have the array that contains a value “type” I want to search the array for the specific “types” and then sort the array based on that. So if the “type” column contains items such as “file” , “link” or “quiz” it would sort alphabetically.

Is this possible? Or should I be thinking of this in a different way?

Can anyone point me in the right direction?

3
  • 1
    begin by posting code! with sample data, such as your tables structures Commented Jul 24, 2014 at 20:27
  • 1
    SELECT column from table WHERE column='something' ORDER BY value - or even LIKE Commented Jul 24, 2014 at 20:27
  • Another option is in_array() and ksort(), sort(), rsort() etc. - pretty broad though. Commented Jul 24, 2014 at 20:38

1 Answer 1

1

In most cases, you'll probably have better results by letting the database do the work, rather than post-processing it in PHP.

As the other folks are saying, some more specifics and code examples would allow us to provide better help, but based on what you've said:

To limit your query results to a specific type, you would add a WHERE clause:

SELECT [whatever columns] FROM table_name WHERE type = 'file'

If you want to select multiple types at the same time:

SELECT [whatever columns] FROM table_name WHERE type IN ('file', 'link', 'quiz')

If you want to order them alphabetically by type:

SELECT [whatever columns] FROM table_name WHERE type IN ('file', 'link', 'quiz') ORDER BY type ASC
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.