dpo69086 2015-05-22 15:20
浏览 54

内部加入不起作用

I have tried everything and nothing is working. I have two tables. The parent table with the primary key and index is childcareinfo and the key is ChildcareID. The child table is users with the primary key of UserID and the foreign key of ChildcareID. The website is set to follow the user through the site using the MM_Username session variable. I have created the following query

SELECT *
FROM childcareinfo INNER JOIN users
 ON childcareinfo.ChildcareID = users.ChildcareID

but the query pulls all the childcares and not just the childcare associated with the user. And then displays the information for the first record in the childcareinfo table and not the associated childcare. I researched and tried the query listed below, but I am told there is a syntax error.

SELECT *
FROM 'users' JOIN 'childcareinfo'
ON 'childcareinfo'.'ChildcareID' = 'users'.'ChildcareID'
Where 'users'.UserName' = $_SESSION[user]'

Thank you so much in advance. This has been the only stop in this website and has been ongoing for three long weeks. I need help to jump this hurdle. Cheers!

  • 写回答

1条回答 默认 最新

  • duan02468 2015-05-22 15:27
    关注

    I would rewrite your second query this way:

    SELECT *
    FROM users JOIN childcareinfo
    ON childcareinfo.ChildcareID = users.ChildcareID
    Where users.UserName = "$_SESSION['user']"
    

    anyway note that you had a typo here:

    Where 'users'.UserName' = $_SESSION[user]'
    

    you should have written:

    Where 'users'.'UserName' = "$_SESSION['user']"
    

    Actually you should use ' or " to wrap strings that you pass to the database and not table/column names. Also in arrays (like $_SESSION) if you reference a key in an associative array you need to wrap it with ''. Only indexes can be put without.

    Last but not least you are doing a MYSQL query that is indipendent from the tool you use to access mysql (PHPMYADMIN) or the IDE you write your code in (DREAMWEAVER)

    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向