合并查询结果
是否有可能将两个不同的查询结果合并到一个结果提要中?
我的网站中有两种类型的内容,一种基于 WordPress 网络并引入 链接到帖子, 标题, 博客名称, 图片(根据博客文章内容生成), 日期。
另一个是一组用户添加的音乐链接并引入 链接到音乐, 音乐名称、 艺术家姓名, 图片(上传图片保存到数据库的路径), 日期。 流派标签列表(序列化数组)
我尝试了一个联合,但是尽管这些列都生成相同类别的内容,但实际内容以及它们的输出方式完全不同。
我可以做什么来结合所有这些?有没有办法从联合查询中找出它们当前来自哪个表?然后我可以使用 if 语句来决定如何输出内容。
Is it at all possible to combine two different query results into one feed of results?
I have two types of content in my site, one is based upon a wordpress network and brings in
Link to post,
Title,
Blog Name,
Image (generated from blog post content),
Date.
the other is a set of user added music links and brings in
Link to music,
Name of music,
Name of artist,
Image (path of uploaded image saved to database),
Date.
List of genres tags (a serialised array)
I tried a union, however despite how these columns all generate the same category of content, the actual contents and therefore how they are output is completely different.
What can I do to combine all of these? Is there a way to figure out which table they are currently from from the union query? Then I could use an if statement to decide how to output the contents.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用 UNION,您将能够添加一个额外的字段,即“类型”(即 0 = 博客,1 = 音乐等),
然后在应用程序的前端从该字段检索数据,然后使用来决定它实际上是什么类型/要包含哪些元素。
If you use a UNION you would be able to add in a extra field which is the 'type' (i.e. 0 = Blog, 1 = Music, etc.)
Then on the front end of the application retrieve data from that field and then use that to decide what type it actually is / which elements to include.