帮助在PHP脚本中编写SQL语句 [英] Help writing SQL statement in PHP script
问题描述
这可能是错误的组,但是......
以下是我的数据示例:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
6 25
2 30
2 35
3 35
正如你所看到的,entry_id'的2和3都属于cat_id 30和35
我用我的脚本捕获了cat_id'的30和35,所以我需要所有
entry_id'属于BOTH cat_id 30和35.
我试过从myTable中选择entry_id,其中cat_id =''30''和cat_id =
''35''但显然这是不正确的。
有人可以帮忙吗?谢谢...
This might be in the wrong group, but...
Here is an example of my data:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
6 25
2 30
2 35
3 35
As you can see, entry_id''s 2 and 3 both belong to cat_id 30 and 35
I have captured the cat_id''s 30 and 35 with my script, so I need all
entry_id''s that belong to BOTH cat_id 30 and 35.
I tried "Select entry_id from myTable where cat_id = ''30'' and cat_id =
''35'' but obviously that is incorrect.
Can someone help? Thanks...
推荐答案
Chuck Cheeze写道:
Chuck Cheeze wrote:
这可能是在错误的群体,但是...
以下是我的数据示例:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
6 25
2 30
2 35
3 35
如你所见,entry_id' 2和3都属于cat_id 30和35
我用我的脚本捕获了cat_id的30和35,所以我需要所有
entry_id'属于BOTH cat_id 30和35.
我试过从myTable中选择entry_id,其中cat_id =''30''和cat_id =
''35''但显然这是不正确的。
有人可以帮忙吗?谢谢......
This might be in the wrong group, but...
Here is an example of my data:
entry_id cat_id
1 20
2 25
3 30
4 25
5 35
6 25
2 30
2 35
3 35
As you can see, entry_id''s 2 and 3 both belong to cat_id 30 and 35
I have captured the cat_id''s 30 and 35 with my script, so I need all
entry_id''s that belong to BOTH cat_id 30 and 35.
I tried "Select entry_id from myTable where cat_id = ''30'' and cat_id =
''35'' but obviously that is incorrect.
Can someone help? Thanks...
这可能是一个更好的方法,但你可以做这样的事情来获得
通过:
There''s probably a nicer way but you can do something like this to get
through:
q =" SELECT`intry_id`,`cat_id` FROM`myTable` WHERE`cat_id` =''30''
或``cat_id` ='''35'';
q = "SELECT `entry_id`, `cat_id` FROM `myTable` WHERE `cat_id` = ''30''
OR `cat_id` = ''35'';
res =
这篇关于帮助在PHP脚本中编写SQL语句的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!