MySqlRuben
Programmer
Hi!
I'm really new to MySql and I was wondering if someone could help get a better understanding of the mechanics of this language.
For example, I have two tables: one called 'articles' and other called 'autors'. What I want is to select all the columns from the 'articles' table, based on the article name, and then select all the columns from the 'autors' table, based on the autor of that article. So I came up with the following php code:
It works, but I'm worried about its efficiency, because after all it's two querys. Is there a way to, with just one single query statement, do it all? Also, could you point me to some article or site that talks about the different query statements?
I'm really new to MySql and I was wondering if someone could help get a better understanding of the mechanics of this language.
For example, I have two tables: one called 'articles' and other called 'autors'. What I want is to select all the columns from the 'articles' table, based on the article name, and then select all the columns from the 'autors' table, based on the autor of that article. So I came up with the following php code:
Code:
$article_name = $_POST['article'];
$query = "SELECT * FROM articles WHERE title='".$article_name."'";
$result = mysql_query($query);
if($result){
while($row = mysql_fetch_array($result)){
$search_autor = $row['autor'];
}
$query_autor = "SELECT * FROM autors WHERE name='".$search_autor."'";
$result_autor = mysql_query($query_autor);
if($result_autor){
//echoes out all the results
}
}
It works, but I'm worried about its efficiency, because after all it's two querys. Is there a way to, with just one single query statement, do it all? Also, could you point me to some article or site that talks about the different query statements?