ivy
08-06-2007, 07:28 PM
Hello there
Some much needed help required please - it's driving me crazy!
I have a mysql select query in php and would like to...
select all
from a table left joined to another table
where
table1.column1 = "1"
AND
table2.column1 = "1"
AND
this is where it gets tricky for me!
table1.column2 = "1"
OR
table2.column2 = "1"
So far, this is what I am using, and... it doesn't work!!!!
$check_id = mysql_query (' SELECT * FROM
(
categories, subcategories
LEFT JOIN subcategories
ON categories.cid = subcategories.scat_ref
)
WHERE
categories.clink = "'.$this.'"
OR subcategories.slink = "'.$this.'"
AND categories.cdisplay = "1"
AND subcategories.sdisplay = "1"
');
I have done my research and found that OR statements should follow AND statements and so changed to this:
$check_id = mysql_query (' SELECT * FROM
(
categories, subcategories
LEFT JOIN subcategories
ON categories.cid = subcategories.scat_ref
)
WHERE
categories.cdisplay = "1"
AND subcategories.sdisplay = "1"
AND categories.clink = "'.$this.'"
OR subcategories.slink = "'.$this.'"
');
But it still doesn't work!
Help would be really appreciated!
(edited only to change coding to php after reading sticky thread!)
Some much needed help required please - it's driving me crazy!
I have a mysql select query in php and would like to...
select all
from a table left joined to another table
where
table1.column1 = "1"
AND
table2.column1 = "1"
AND
this is where it gets tricky for me!
table1.column2 = "1"
OR
table2.column2 = "1"
So far, this is what I am using, and... it doesn't work!!!!
$check_id = mysql_query (' SELECT * FROM
(
categories, subcategories
LEFT JOIN subcategories
ON categories.cid = subcategories.scat_ref
)
WHERE
categories.clink = "'.$this.'"
OR subcategories.slink = "'.$this.'"
AND categories.cdisplay = "1"
AND subcategories.sdisplay = "1"
');
I have done my research and found that OR statements should follow AND statements and so changed to this:
$check_id = mysql_query (' SELECT * FROM
(
categories, subcategories
LEFT JOIN subcategories
ON categories.cid = subcategories.scat_ref
)
WHERE
categories.cdisplay = "1"
AND subcategories.sdisplay = "1"
AND categories.clink = "'.$this.'"
OR subcategories.slink = "'.$this.'"
');
But it still doesn't work!
Help would be really appreciated!
(edited only to change coding to php after reading sticky thread!)