Jump to content

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

Edited by goldfishdancer
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.