Answered: Which query should I use to show random questions from particular tag ?

Post date: 2021-02-22 23:03:06
Views: 93

Tags are stored in the database by linking posts (table qa_posts) to words (table qa_words) with an associative table qa_posttags. To restrict your query to a particular tag you need to join the posts table to the words table via that associative table.

SELECT q.postid
FROM qa_posts q
  INNER JOIN qa_posttags t ON q.postid=t.postid
  INNER JOIN qa_words w ON t.wordid=w.wordid
WHERE w.word='tagname';

So your statement should probably look like this:

qa_db_read_one_assoc(qa_db_query_sub('SELECT * FROM ^posts q INNER JOIN ^posttags t ON q.postid=t.postid INNER JOIN ^words w ON t.wordid=w.wordid WHERE q.type="Q" AND w.word=$ ORDER BY rand() LIMIT 1;', $tagname));

Please click Here to read the full story.
 
Other Top and Latest Questions:
China is still years behind the U.S. despite Huawei's breakthrough chips, Raimondo tells '60 Minutes'
Why Apple is betting big on India
Supreme Court will take up the legal fight over ghost guns, firearms without serial numbers
Charles Buhler reactionless drive math error?
I eat salmon, love it. What are other good-guy sources of fat?
All Elite Wrestling: Dynamite: AEW Dynasty 2024
Buckle up. These stocks could see big moves in reaction to earnings this week
A pullback in this biotech stock has created a buying opportunity, according to the charts
EU threatens to suspend TikTok Lite’s money-for-views program over addiction fears
Verizon reports fewer quarterly subscriber losses on flexible plan demand