K
K
KickMicro2017-04-11 18:20:50
MySQL
KickMicro, 2017-04-11 18:20:50

How to select records in sql, knowing their id?

I have a table that stores links to favorite articles by users. To select the id of all the posts that the user has marked as favorite, you need to apply this code:

SELECT `targetid` FROM `chosenlink` WHERE `type`=1 AND `userid`=".$userinfo['id']

type is the record type; 1 - article; 2 - question and so on.
And so we have id of all articles which the user added to favorites.
how can I further identify all the articles with the id that we received with the code above (it is clear that mysqli_fetch_array comes after this)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Eremin, 2017-04-11
@KickMicro

The question is a little not clear
So far, we can say for sure that the search is done like this. You just have to substitute your set of ids
select * from table where id in (1, 2, 3, 4 ....)

A
anton_lazarev, 2017-04-11
@anton_lazarev

If, of course, I correctly understood the question, then you need JOIN , something like this:

SELECT `t2`.*  FROM `chosenlink` `t1` JOIN `table` `t2` ON `t1'.`targetid` = `t2`.`id` WHERE `type`=1 AND `userid`=".$userinfo['id']

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question