goldfishdancer Posted March 5, 2013 Share Posted March 5, 2013 (edited) This is mysql code im trying to run: SELECT i.id, i.courseid, i.title, i.info, i.lasteditedby, u.id, u.forename, u.surname FROM courseinformation as i JOIN users AS u ON (i.lasteditedby = u.id) WHERE i.courseid = :courseid ORDER BY i.id desc LIMIT 2; Im getting this error : /* SQL Error (1064): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ':courseid ORDER BY i.id desc LIMIT 2' at line 1 */ My aim is to get id, courseid, title, info, lasteditedby from CourseInformation table, and then Id, forename and surname from user table. Where the userid is the same as lasteditedby. I really can't see what sql syntax is wrong as i've used :courseid in other pdo sql querys that ive run for reference, this is my php code with that sql in $courseid = 'G11111'; $sql = "SELECT i.id, i.courseid, i.title, i.info, i.lasteditedby, u.id, u.forename, u.surname FROM courseinformation as i JOIN users AS u ON (i.lasteditedby = u.id) WHERE i.courseid = :courseid ORDER BY i.id desc LIMIT 2"; $sql->bindParam(":courseid", $courseid); $sql->execute(); foreach ($db->query($sql) as $row) { echo '<div class="announceTitle">'; echo $row['title'].'<br />'; echo $row['forename'].' '.$row['surname'].'<br />'; echo '</div> <div class="announceText">'; echo $row['info']; echo '</div> <br /> <br />'; } Could anyone please point me in the direction as to what is wrong?Thanks for reading Edited March 5, 2013 by goldfishdancer Quote Link to comment https://forums.phpfreaks.com/topic/275271-selecting-with-a-join-and-a-where-and-an-order-by-and-a-limit-error/ Share on other sites More sharing options...
fenway Posted March 9, 2013 Share Posted March 9, 2013 Well, it's clear that whatever you think PDO is doing to that query, it's not -- there is no colon in the column name. Quote Link to comment https://forums.phpfreaks.com/topic/275271-selecting-with-a-join-and-a-where-and-an-order-by-and-a-limit-error/#findComment-1417740 Share on other sites More sharing options...
Jessica Posted March 9, 2013 Share Posted March 9, 2013 Don't you have to prepare before you can bind? Quote Link to comment https://forums.phpfreaks.com/topic/275271-selecting-with-a-join-and-a-where-and-an-order-by-and-a-limit-error/#findComment-1417747 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.