Jump to content

left join


techker

Recommended Posts

hey guy i doing a litle script for renting dvd's..

 

i got the DB OUT for rentals and employee for id of the person renting it..

 

So on my page account i wan't to list the rented dvd's from the employee

 

need to check the OUT database and the Location database for the movie title and pics..

 

i got this but i got a syntax error..

 

$query = "SELECT OUT.Employer,OUT.DVD_ID, Location.L_ID ".
"FROM OUT, Location ".
"WHERE OUT.DVD_ID = Location.L_ID AND OUT.Employer = $Account";

 

 

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 'OUT, Location WHERE OUT.DVD_ID = Location.L_ID AND OUT.Employer = techker' at line 1

 

Link to comment
Share on other sites

You can use reserved words, just make sure you wrap them in slanted apostrophes. There's no need for you to have a full stop at the end of each line either.

 

$sql = "SELECT `OUT`.`Employer`,`OUT`.`DVD_ID`, `Location`.`L_ID` 
            FROM `OUT`, `Location`
            WHERE `OUT`.`DVD_ID` = `Location`.`L_ID` AND `OUT`.`Employer` = '{$Account}'";

 

If your not getting any results ensure a result set is being returned and no errors are occurring with the mysql_errors() function. If everything's fine, you probably don't have any results matching that query.

 

Moreover, with joins such as these you can easily get ambiguity so be careful.

Link to comment
Share on other sites

still doesnt work..fill the database..

 

so my goal is to check the rentals done by the loggin in user.

 

so in rentals is have

R_ID DVD_ID Employee LP Date

 

then i want to go in the Locations(dvd's) and get the DVD info that he rented.(DVD_ID)

L_ID Titre Date Prix Categorie Image Status UPC

 

so basically when he goes to the account page it shows his rented movies..

Link to comment
Share on other sites

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.