I have two tables that I want to select from. I have a table called articles which stores various articles for my content management system and I have another called articles_meta_data that stores meta data for the articles table. In order to get an article’s meta data, you select from articles_meta_data using the article Id. My code is here and works perfectly. Is there a way I can optimize the code and make it faster?
$result = mysql_query("SELECT * FROM articles");
while ($row = mysql_fetch_object($result)) {
$result2 = mysql_query("SELECT * FROM articles_meta_data WHERE article_ID=" . $row->ID);
while ($row2 = mysql_fetch_object($result2)) {
var_dump($row2);
}
}
join the tables so you will only query the database once, eg
To further lean more about join, please see the link below