简体   繁体   English

如何进行选择查询以从一个表中选择数据并将结果提供给另一个选择

[英]How to make select query to select data from one table and results give to another select

I want to make table in HTML. 我想用HTML制作表格。 First column should be names of people and next columns should be date of lessons. 第一列应为人员姓名,下一列应为课程日期。 I would like to make something like school attendance. 我想上学。 When someone was in class the cell should be green when I click on it otherwise it should be white. 当有人在上课时,单击该单元格时该单元格应为绿色,否则应为白色。 I want to select names of users and names of lessons from database. 我想从数据库中选择用户名和课程名。 How shoul I write good select query that can do what i want? 我如何编写可以执行我想要的操作的优质选择查询?

SCHEME OF TABLE USERS: - id (tinyint) - name (varchar) - password (varchar) md5 表格用户方案: -id (tinyint)- 名称 (varchar)- 密码 (varchar)md5

SCHEME OF TABLE LESSONS: - id (tinyint) - name (date) 表课程表: -id (tinyint)- 名称 (日期)

I make an example of data that I want to get: 我举一个我想获取的数据的例子:

http://jsfiddle.net/k8UgT/207/ http://jsfiddle.net/k8UgT/207/

HTML: HTML:

<table>
    <tr>
        <th>NAME</th>
        <th>25.10.</th>
        <th>26.10.</th>
    </tr>
        <tr>
        <td>Jack</td>
        <td></td>
        <td></td>
    </tr>
    <tr>
        <td>Sam</td>
        <td></td>
        <td></td>
    </tr>
</table>

JQUERY: JQUERY:

$( function() {
  $('td').click( function() {
    $(this).toggleClass('on');
} )
});

You should have a new table, let's say users_lessons_date with the following structure: 您应该有一个新表,假设具有以下结构的users_lessons_date

  • id ID
  • userId (int) - foreign key table_users userId (int) -外键table_users
  • lessonId (int) - foreigg key lessons lessonId (int) -foreigg关键课程
  • dateOfLesson (datetime) dateOfLesson (datetime)

And your query, if you're using mysql and you want all date where a user was to lesson, will be: 如果您使用的是mysql,并且希望用户上课的所有日期,则查询将是:

select dateOfLesson, lessons.name as lessonName, table_users.name = userName
from users_lessons_date uld
join table_users u on ( uld.userId = u.id )
join lessons l on (uld.lessonId = l.id)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用一个查询的结果进行另一个查询并填充 HTML 选择 - Using the results of one query to make another query and populate an HTML select 从选择查询中的另一个表中全选 - Select all from another table in select query PHP-如何从表中选择一个查询 - PHP - how to select from a table one query 从一个表中选择,并从同一查询中的另一个表计数 - Select from one table, and count from another table in same query 从另一个查询没有返回结果的表中选择所有 - Select all from table where another query retuns no results 从一个表中选择结果,并为每一行从另一张表中选择具有相同ID的所有行 - Select results from one table and for each row select all rows that have the same id from another table 从一个条件为的表中检索数据,并在一个SELECT查询中检查另一个表中的记录 - Retrieve data from a table with a condition where and check the record in another table in one SELECT query 从一个表中选择数据,按另一表中的数据总和排列 - Select data from one table, arrange by a sum of data from another MySQL我可以从一个表还是另一个表中选择数据? - MySQL Can I Select Data from One table OR another Table? MYSQL-如何从第一个表返回数组,并在一个查询中使用该数组从另一个表中选择? - MYSQL - How to return array from first table and select from another table using that array in one query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM