[英]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
:
(int)
- foreign key table_users userId (int)
-外键table_users (int)
- foreigg key lessons lessonId (int)
-foreigg关键课程 (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.