Jump to content

selecting with a join and a where and an order by and a limit - error


goldfishdancer

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.