B
B
BonBon Slick2017-03-23 00:14:32
MySQL
BonBon Slick, 2017-03-23 00:14:32

How to sort by title if we only have id?

$watchlist = DB::table('user_watchlist')
            ->where('user_id', $userID)
            ->orderBy('id', $watchlistOrderType)
            ->limit(4)
            ->get();

As you can see, in this table we have a list of watch lists, similar to a wishlist in stores, but we need to sort not by ID, but by the Title field, which is in another table. As an option, add to., sorting field. But I'm not sure if this is the right way.
How to do this?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander Aksentiev, 2017-03-23
@BonBonSlick

join, and then order
what other options are there

P
Pavel, 2017-03-23
@electronik777

$watchlist = DB::table('user_watchlist')
            ->where('user_id', $userID)
            ->orderBy('title ', $watchlistOrderType)
            ->limit(4)
            ->get();

not?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question