简体   繁体   中英

Three times INNER JOIN SELECT

I've a page where I want to use 3 times INNER JOIN, Because log_items have a row called 'price'. When I do INNER join with log_mobs & log_mitem everything goes fine, He gets all information from $_GET['id'] combined with ['g'] but when I join with log_items he shows all rows from the table 'log_items'

I want to show on the page, the items the MOB have next to that I want to show the price. But he shows all those information from 'log_items' I need to show items from 'log_mitem' but I need to get those prices from 'log_items'

if (isset($_GET['id']) && isset($_GET['g']))
{
    $id     = $db->real_escape_string(trim($_GET['id']));
    $g     = $db->real_escape_string(trim($_GET['g']));
    $mobitem    = $db->query("SELECT * FROM log_mobs INNER JOIN log_mitem INNER JOIN log_items ON log_mobs.name = log_mitem.mobname AND log_mobs.game = log_mitem.game WHERE log_mobs.name = '".$id."' AND log_mitem.game = '".$g."'") or die($db->error);
?>

I think your SQL request should look something like this:

select * from log_mobs
inner join log_mitem on log_mobs.name = log_mitem.mobname
inner join log_items on log_items.column = theOtherSideOfTheJointure.column

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM