我将这两个 MySQL 表放在同一个数据库中,我正在将其用于网站之类的论坛。我的问题是关于根据两者之间的“user_id”链接在表“topics”中加入新字段的正确查询。
表“users”,其中字段“user_id”在注册时创建,自动递增:
USERS ╔═════════╦══════════╦═══════════╦══════════╦════════╗ ║ user_id ║ username ║ firstname ║ lastname ║ etc... ║ ╠═════════╬══════════╬═══════════╬══════════╬════════╣ ║ 1 ║ JJJJ ║ John ║ Johnson ║ etc... ║ ║ 2 ║ MMMM ║ Max ║ Maxman ║ etc... ║ ║ 3 ║ AAAA ║ Alex ║ Aleckson ║ etc... ║ ╚═════════╩══════════╩═══════════╩══════════╩════════╝
Table "topics", where "user_id" is taken from the other table when any user submits what you would normally call a new thread on forum websites.
TOPICS ╔══════════╦═════════════╦═══════════════════╦═════════╦═════════╗ ║ topic_id ║ description ║ datetime ║ user_id ║ etc ... ║ ╠══════════╬═════════════╬═══════════════════╬═════════╬═════════╣ ║ 1 ║ bla bla ║ dd mon yyyy hh:mi ║ 3 ║ etc... ║ ║ 2 ║ bla bla ║ dd mon yyyy hh:mi ║ 3 ║ etc... ║ ║ 3 ║ bla bla ║ dd mon yyyy hh:mi ║ 2 ║ etc... ║ ╚══════════╩═════════════╩═══════════════════╩═════════╩═════════╝
I can confirm connection with the db is established succesfully in PHP. The db name is "website". I am running the following query with no success, for what I;d like to be the result you see in the third table ( right joining the last field).
mysql_query("SELECT topics.user_id, users.user_id
FROM website.topics
JOIN website.users ON topics.who_posted_hangout;");
TOPICS ╔══════════╦═════════════╦═══════════════════╦═════════╦═════╦═══════════════════╗ ║ topic_id ║ description ║ datetime ║ user_id ║ etc ║ username ║ ╠══════════╬═════════════╬═══════════════════╬═════════╬═════╬═══════════════════╣ ║ 1 ║ bla bla ║ dd mon yyyy hh:mi ║ 3 ║ etc ║ AAAA ║ ║ 2 ║ bla bla ║ dd mon yyyy hh:mi ║ 3 ║ etc ║ AAAA ║ ║ 3 ║ bla bla ║ dd mon yyyy hh:mi ║ 2 ║ etc ║ MMMM ║ ╚══════════╩═════════════╩═══════════════════╩═════════╩═════╩═══════════════════╝
我使用了一个我在某处看到的示例来编写查询,但有些东西对我来说没有意义:
<pre> </pre>之间标签。
最佳答案
尝试:
'SELECT * FROM topics INNER JOIN users ON topics.user_id = users.user_id WHERE topics.user_id = the_user_id';
关于php - 具有重复字段的 MySQL JOIN 查询语法 - "database.table.field",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35121400/
我正在尝试测试是否存在表单。我是Rails新手。我的new.html.erb_spec.rb文件的内容是:require'spec_helper'describe"messages/new.html.erb"doit"shouldrendertheform"dorender'/messages/new.html.erb'reponse.shouldhave_form_putting_to(@message)with_submit_buttonendendView本身,new.html.erb,有代码:当我运行rspec时,它失败了:1)messages/new.html.erbshou
我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-
我想安装一个带有一些身份验证的私有(private)Rubygem服务器。我希望能够使用公共(public)Ubuntu服务器托管内部gem。我读到了http://docs.rubygems.org/read/chapter/18.但是那个没有身份验证-如我所见。然后我读到了https://github.com/cwninja/geminabox.但是当我使用基本身份验证(他们在他们的Wiki中有)时,它会提示从我的服务器获取源。所以。如何制作带有身份验证的私有(private)Rubygem服务器?这是不可能的吗?谢谢。编辑:Geminabox问题。我尝试“捆绑”以安装新的gem..
我正在用Ruby编写一个简单的程序来检查域列表是否被占用。基本上它循环遍历列表,并使用以下函数进行检查。require'rubygems'require'whois'defcheck_domain(domain)c=Whois::Client.newc.query("google.com").available?end程序不断出错(即使我在google.com中进行硬编码),并打印以下消息。鉴于该程序非常简单,我已经没有什么想法了-有什么建议吗?/Library/Ruby/Gems/1.8/gems/whois-2.0.2/lib/whois/server/adapters/base.
我在MiniTest::Spec和Capybara中使用以下规范:find_field('Email').must_have_css('[autofocus]')检查名为“电子邮件”的字段是否具有autofocus属性。doc说如下:has_css?(path,options={})ChecksifagivenCSSselectorisonthepageorcurrentnode.据我了解,字段“Email”是一个节点,因此调用must_have_css绝对有效!我做错了什么? 最佳答案 通过JonasNicklas得到了答案:No
为了将Cucumber用于命令行脚本,我按照提供的说明安装了arubagem。它在我的Gemfile中,我可以验证是否安装了正确的版本并且我已经包含了require'aruba/cucumber'在'features/env.rb'中为了确保它能正常工作,我写了以下场景:@announceScenario:Testingcucumber/arubaGivenablankslateThentheoutputfrom"ls-la"shouldcontain"drw"假设事情应该失败。它确实失败了,但失败的原因是错误的:@announceScenario:Testingcucumber/ar
我有一个表单,其中有很多字段取自数组(而不是模型或对象)。我如何验证这些字段的存在?solve_problem_pathdo|f|%>... 最佳答案 创建一个简单的类来包装请求参数并使用ActiveModel::Validations。#definedsomewhere,atthesimplest:require'ostruct'classSolvetrue#youcouldevencheckthesolutionwithavalidatorvalidatedoerrors.add(:base,"WRONG!!!")unlesss
我想向我的Controller传递一个参数,它是一个简单的复选框,但我不知道如何在模型的form_for中引入它,这是我的观点:{:id=>'go_finance'}do|f|%>Transferirde:para:Entrada:"input",:placeholder=>"Quantofoiganho?"%>Saída:"output",:placeholder=>"Quantofoigasto?"%>Nota:我想做一个额外的复选框,但我该怎么做,模型中没有一个对象,而是一个要检查的对象,以便在Controller中创建一个ifelse,如果没有检查,请帮助我,非常感谢,谢谢
我想设置一个默认日期,例如实际日期,我该如何设置?还有如何在组合框中设置默认值顺便问一下,date_field_tag和date_field之间有什么区别? 最佳答案 试试这个:将默认日期作为第二个参数传递。youcorrectlysetthedefaultvalueofcomboboxasshowninyourquestion. 关于ruby-on-rails-date_field_tag,如何设置默认日期?[rails上的ruby],我们在StackOverflow上找到一个类似的问
我遵循MichaelHartl的“RubyonRails教程:学习Web开发”,并创建了检查用户名和电子邮件长度有效性的测试(名称最多50个字符,电子邮件最多255个字符)。test/helpers/application_helper_test.rb的内容是:require'test_helper'classApplicationHelperTest在运行bundleexecraketest时,所有测试都通过了,但我看到以下消息在最后被标记为错误:ERROR["test_full_title_helper",ApplicationHelperTest,1.820016791]test