Answer the question
In order to leave comments, you need to log in
How to display data from two tables by key field?
Good afternoon!
There is a table example1 which has the following fields: id, title, description, keyarticle .
And the second table is example2 which has the following fields: id, photo, linkon, keyarticle .
Can you please tell me how to correctly link two tables and display them in one whole?
Something tried like this:
SELECT * FROM example1, example2 WHERE example1.keyArticle = example2.keyArticle
for($i = 0; $i < count($getArticle); $i++) {
echo $getArticle[$i]["title"]."<br>";
/* */
}
Answer the question
In order to leave comments, you need to log in
SELECT * FROM example1 e1 INNER JOIN example2 e2 ON e1.keyArticle = e2.keyArticle
Repetitions will be in any case if this relationship is one-to-many. Try using GROUP BY.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question