English 中文(简体)
从我的sql到php获得同样的财产
原标题:getting same property from mysql with php
  • 时间:2009-12-02 08:40:50
  •  标签:
  • php
  • mysql

浏览器有1个现有用户,还有另一个用户,目前用户正在访问。

例如,用户1已上下了照片,用户2也上下了照片。

* 选自用户:id=用户1id或id=用户2id 和免疫有效载荷= 页: 1

is this query is correct or not but it is not working for me..........!! i want a working query same as above not as select * from users where imguploaded=1

问题回答

由于优先程度,试图将你带括号的顺序排列在后面......

select * from users where (id= user1id  or id= user2id ) and imguploaded= 1 

如果你不 t我的q,就会把 default事摆在优先地位,并像这样解释问题:

select * from users where id= user1id  or (id= user2id  and imguploaded= 1 )

这将不产生预期结果。

检查用户是否实际上下了照片,可以做到:

select COUNT(*) as count from users where (id= user1id  or id= user2id ) and imguploaded= 1 

之后,如果计算=2

为什么你们想要这样的东西?

任何方面......都会形成某种行动表,如<编码>、行动、。 然后创建<代码>用户_action。 表格如<代码>id,用户_id,行动_id。 然后,请你取得成果。

因此,你储存数据指的是表格,而不是用其行动数据提升用户数据。 这样,你也能够方便地扩大行动范围,比较采取行动的使用者。

select * from users where (id= user1id  and imguploaded= 1 ) and (id= user2id and imguploaded= 1 ) 

如何加入?

query = "SELECT * FROM users AS first JOIN users AS second ON first.imguploaded = second.imguploaded WHERE first.userid = $user1 AND second.userid = $user2"

This query would take the two users, and if they have the same attribute (imguploaded is the same for both), return both rows, you can then select what you need. You can add more attributes to the ON clause, for example: ON first.imguploaded = second.imguploaded OR ( first.imgdloaded = second.imgdloaded AND first.somethingelseuploaded = second.somethingelseuploaded).

这样(加上我方言中的“ ON”条款),你就可以将一切属性合并起来,但你必须把括号(和)放在适当的位置。 当然,如果你不提,MySQL服务器将只是按序读。

这是你们需要的吗?





相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签