I am having great difficulty getting a query to work with multiple conditions. I have a very basic understanding, hence the two queries below (one commented out). I understand a smaller and more precise query would be returned by using INNER JOIN. Both queries work fine until I try to add an addition condition to the query: "AND links.menu_name = $menu_name".
$query = mysql_query("
SELECT links.link_name, links.menu_name, nodes.url, nodes.file_path
FROM links, nodes
WHERE links.node_id = nodes.node_id");
//AND links.menu_name = $menu_name
/*
$query = mysql_query("
SELECT link_name, menu_name, url, file_path
FROM nodes
INNER JOIN links
ON links.node_id = nodes.node_id
ON links.menu_name = $menu_name");
*/
ATM things work if I do the additional condition check inside a while loop (see below), but I'm concerned this may be slower that adding the condition on the original query which I'm having trouble getting to work, particularly on larger returned sets. Can someone please shed some clarity.
while ($row = mysql_fetch_assoc($query)) {
if ($row['menu_name'] == $menu_name){
//CHECK TO SEE IF FILE EXISTS
$check_file = $this->path['content'] . $row['file_path'];
if (is_file($check_file)){
$a_href = '<li><a href="' . $this->base_path . $row['url'] . '">' . $row['link_name'] . '</a></li>';
$menu_row .= $a_href;
}
else {
//echo 'illegal link';
$a_href = null;
}
}
}