0

I have 2 tables: tbImages, tbUsers

tbImages has lots of paths of images with unique ids
tbUsers has lots of users with unique ids...

I will code a page that make a delivery of images...This page will show all images ordering by id... The admin will select 7 images to send it to some user by email... I will have to register when and how many times some user has received that image (a 3rd table maybe)... Here is the problem... I'll have to ORDER images by date of register.. Images already sent have to appear at end of that delivery page...

What is the better way to do this? tbImages has lots of columns one for each user? A 3rd table (tbDelivered) one row each user with column 'images received'? ?How to make this SELECT to show already sent images at end?

4

2 回答 2

1

将您与用户 ID 相关联的第三张表imageID(关系表)。然后,您可以JOIN在查询中使用语句。例如:

relational_table
  imageID
  userID
  sendCount

查询可能是:

SELECT sendCount
FROM relational_table
WHERE imageID = $imageID
AND userID = $userID

这将使您返回该图像已发送给该用户的次数。

于 2013-03-05T22:56:30.883 回答
0

您将必须创建一个包含以下内容的第三个表:

  • 图像标识
  • 用户标识
  • 数量

您将创建一个如下所示的 select 语句:

SELECT tbImages.imageID, tbDelivered.quantity
FROM tbImages, tbDelivered
WHERE tbImages.imageID = tbDelivered.imageID;

要显示尚未交付的内容,您必须在其末尾添加:

AND quantity = 0;

我希望这有帮助

于 2013-03-05T23:45:37.257 回答