简体   繁体   English

在MySQL和关系表中加入JOIN错误

[英]JOIN in MySQL and relational tables error

I have three tables, "food","member" and "member_food". 我有三个表,“食物”,“成员”和“ member_food”。 I'm trying to make an update user page where a collection of tags are prepopulated by the data in "member_food". 我正在尝试创建一个更新用户页面,其中“ member_food”中的数据预填充了标记的集合。

I have debugged the ID sending from the previous page which allows me to select the entry I wish to query, ID:4 . 我已经调试了从上一页发送的ID,该ID使我可以选择要查询的条目ID:4

$query = "SELECT * FROM `food` left join `member_food` on food.entityid = member_food.food_id WHERE member_id = '$id'";
            //Breakfast
            $breakfastresult1 = $mysqli->query($query);

echo '<select name="breakfast1">';
        while($BreakfastData1 = mysqli_fetch_array($breakfastresult1, MYSQL_ASSOC))
        {
            echo '<p><option value="' . htmlspecialchars($BreakfastData1['member_food.food_id']) . '">' 
                . htmlspecialchars($BreakfastData1['member_food.food_name']) 
                . '</option>'
                . '</p>';        
        }
echo '</select>';

However, the select fields appear to be empty. 但是,选择字段似乎为空。 I think it's not pulling the correct values from my leftjoin table. 我认为这不是从我的leftjoin表中提取正确的值。

Here is an example of my member_food table: 这是我的member_food表的示例: 在此处输入图片说明

food table: 餐桌:

在此处输入图片说明

编辑此内容,首先需要输入错误(左+联接中缺少空格),其次您需要知道哪个表member_id属于

     $query = "SELECT * FROM `food` as f left join `member_food` as mf on f.entityid = mf.food_id WHERE mf.member_id = '$id'";

You can use this to plan your joins correctly. 您可以使用它来正确地计划您的联接。 And, as Abdul pointed out, typos are bad ;) 而且,正如阿卜杜勒指出的那样,错别字很糟糕;)

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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