简体   繁体   English

SQL查询给出错误?

[英]SQL query giving error?

$bilgi= mysql_query("SELECT age,wname,slid,sex FROM user AND city WHERE user.ci_name=(SELECT ci_id FROM city WHERE ci_name='$ciname')");
while($sutun= mysql_fetch_array($bilgi))

This is my statement of query. 这是我的查询声明。 This gives me error and the error is supplied argument is not valid MySQL result in resource in .... 这给了我错误,并且提供的错误参数无效MySQL导致资源中的....

Now let me explain what I am doing. 现在让我解释一下我在做什么。 I am sending some city name to my database in order to find the unique number of the city. 我正在向我的数据库发送一些城市名称,以便找到该城市的唯一编号。 I send Istanbul and it's id is 2 in my database. 我发送伊斯坦布尔,我的数据库中的id为2。 I have 2 tables, 1 is city the other one is user. 我有2个表,1个是城市,另一个是用户。 User table has age,wname,sex,slid; 用户表有年龄,wname,性别,滑动; and ci_name part that is foreign key with the city_id. 和ci_name部分是city_id的外键。 city_id is the primary key of the city table. city_id是城市表的主键。 I want to find the age, wname, slid and sex of Istanbul. 我想找到伊斯坦布尔的年龄,wname,滑行和性别。

Can anyone help me how can I get throw with this error and find what I want :)? 任何人都可以帮助我如何摆脱这个错误并找到我想要的:)?

$bilgi= mysql_query("SELECT age,wname,slid,sex FROM user, city WHERE user.ci_name=(SELECT ci_id FROM city WHERE ci_name='$ciname')");
    while($sutun= mysql_fetch_array($bilgi))

You had an AND in your FROM section, which isn't valid. 你的FROM部分有一个AND ,这是无效的。

You can use one Query instead of using two like you: 您可以使用一个Query而不是像您一样使用两个:

$query = 'SELECT age,wname,slid,sex FROM user, city WHERE user.ci_name = city.ci_id AND city.name = '".$yourCityNameYouSeek."'';

The only thing I don't get is which table-column your city name is stored. 我唯一没有得到的是你的城市名称存储在哪个表格列中。 In user -table you have ci_name (is that a NAME or an ID)? user ci_name你有ci_name (是NAME还是ID)?

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

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