0

This query works fine with ColdFusion, yet I can't get it to work in PHP. The PHP doesn't like my joins. What is different in the two queries?

<cfquery name="getArt" datasource="mssqlcf_PDartist1">
select * from artwork a
join Categories b on (b.CID = a.CID)
join SubCategories c on (c.CID = b.CID and c.SCID = a.SCID)
where AID = #AID#
order by DisplayOrder
</cfquery>


<?php
$dbname = 'pdartist2';
$table = 'artwork';
$result = mysql_query("SELECT * from artwork") or die(mysql_error());
a join Categories b on (b.CID = a.CID)
join SubCategories c on (c.CID = b.CID and c.SCID = a.SCID)
where AID = $AID
order by DisplayOrder
mysql_free_result($result);
?>
8
  • PHP does not care about your joins. ;) Commented Nov 26, 2011 at 20:46
  • Do you mean they need to be left out? Commented Nov 26, 2011 at 21:04
  • No I mean that PHP (or ColdFusion, for that matter) sends strings to the database server. It does not care in the least whether they contain joins or not. Commented Nov 26, 2011 at 21:10
  • So why does the query work on my Cold Fusion site and not on the PHP site? Could it be that PHP is case sensitive and Cold Fusion is not. Since the tables are named in all lowercase!? Commented Nov 26, 2011 at 21:12
  • Because you have a PHP syntax error right there. This has nothing to do with SQL. Mark's answer points that out very nicely. Commented Nov 26, 2011 at 21:13

1 Answer 1

2

You ended the PHP string too early. The quotes must surround the entire SQL query:

$result = mysql_query("SELECT *
    FROM artwork a
    JOIN Categories b ON b.CID = a.CID
    JOIN SubCategories c ON c.CID = b.CID AND c.SCID = a.SCID
    WHERE AID = $AID
    ORDER BY DisplayOrder") or die(mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.