[英]How can I select * from a table where a UID doesn't exist with a certain value in another table?
I have two
tables and what I'm trying to acheive is to grab a PhotoEmbed
code from the Photos
table so I can then use it to display a photo on the webpage - Each time the webpage is reloaded it will show a new picture. 我有
two
表,而我想要达到的目的是从“ Photos
表中获取一个PhotoEmbed
代码,这样我就可以用它在网页上显示照片-每次重新加载网页时,它都会显示一张新照片。 But I don't want to keep displaying the same picture?! 但是我不想一直显示相同的图片吗? I want to display a new picture each time...So I've set up the following tables but Have no idea how to run a query to actually grab the
SELECT PhotoEmbed FROM Photos WHERE **CURRENT UserID** FROM Seen WHERE Seen **IS NOT EQUAL TO 1**
我想每次显示一张新图片...所以我建立了以下表格,但不知道如何运行查询以实际获取
SELECT PhotoEmbed FROM Photos WHERE **CURRENT UserID** FROM Seen WHERE Seen **IS NOT EQUAL TO 1**
If the Seen
is equal to 1
then run the query again and find a new PhotoEmbed
code. 如果
Seen
等于1
则再次运行查询并找到新的PhotoEmbed
代码。 Would you do this with a query or just select * from Photos and all from Seen
and then USE PHP to determine what embed code to use? 您将使用查询来执行此操作,还是仅从
select * from Photos and all from Seen
,然后select * from Photos and all from Seen
,然后使用PHP确定要使用的嵌入代码?
Below Is a demo of two database tables. 下面是两个数据库表的演示。 On the left there is the
Photos Table
and on the right (starting at userID) there is the Seen
table. 左侧是
Photos Table
,右侧(从userID开始)是Seen
表。
| PhotoID | PhotoEmbed| |UserID | PhotoID |Seen |
| 1 |Filename.jpg| |2 | 1 |1 |
Get all photos which are not in the seen table like this: 像这样获取所有不在可见表中的照片:
SELECT PhotoID,etc from Photos where PhotoID NOT IN (select PhotoID from Seen where UserId = 1)
Given if you insert only viewed images in Seen
table ( seen
column,which I guess is bool
could be removed), if you insert a new image I don't suppose for each user you should populate the table with seen
set to 0. 如果插入只有看的图像由于
Seen
表( seen
列,我猜是bool
可以被删除),如果插入一个新的形象我不认为每个用户,你应该填充表seen
设置为0。
If by any chance the user saw all images consider making a random fetch: 如果有机会用户看到了所有图像,请考虑进行随机获取:
SELECT * FROM PhotosORDER BY RAND() LIMIT 1;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.