简体   繁体   中英

SQL Query , joins and where

I am trying to run a rather simple query, but it seems to return absolutely no result;

$q  = "SELECT DISTINCT c.product_sku, c.compare_at, c.product_discount_id, d.amount FROM #__{vm}_product as c
LEFT OUTER JOIN #__vm_product_discount as d ON d.discount_id = c.product_discount_id WHERE";
$q .= "c.vendor_id='".$_SESSION['ps_vendor_id']."' ";
$q .= "AND #__{vm}_product.product_publish='Y' ";
$q .= "AND #__{vm}_product.isfront='1' ";
$q .= "AND c.isfront='1' ";

There are other queries after the above, but even when I comment out everything and use only one WHERE clause, nothing is returned. When I remove it, it works. All the below code did work until I added the JOIN.

I'm new to using joins, I'm guessing something about them makes the WHERE not work, but maybe I just messed up the code along the way, so perhaps better trained eyes could find an issue here?

Thanks in advance!

In the above code, you do not have any space between the WHERE and the c.vendor_id. So your SQL would look like: blah blah WHEREc.vendor_id= blah blah. So the first thing to try would be to add a space after the WHERE in the first line.

If there's more to this problem than a missing space, please could you post an example of the actual SQL in $q that is being run, rather than the code used to produce it? Your code does not contain a liberal sprinkling of protective measures such as addslashes() or mysql_real_escape_string(), so it's possible that there's something nasty in there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM