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
https://forums.phpfreaks.com/topic/260200-left-join/
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
https://forums.phpfreaks.com/topic/260200-left-join/#findComment-1333669
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
https://forums.phpfreaks.com/topic/260200-left-join/#findComment-1333680
Share on other sites

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.