Hej bokningar
jag vill skriva ut dagensbokningar för en liten frisör i html-tabell, där finns flera personer som jobbar. jag skriver ut först alla frisörer i den första raden i tabellen, sedan bokningar osv... men problemet är att jag inte kan skriva ut alla frisörer och sina respektiva bokningar (allstå dagensbokning....),
Tid Leif Anders Johanna
09.00 X X -
10.00 X - X
11.00 X X X
X= har bokning
- = har ingen bokning
här är det koden som jag har skrivit, men............
<%@ page import="java.sql.*" %>
<%@ page import="java.util.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
<Style>
table{
padding: 0px;
border-collapse: collapse;
}
tr{
border-top: solid 1px black;
border-bottom: solid 1px black;
}
.clsTimeCell{
width: 100px;
}
.clsFrisorCol{
width: 80px;
}
.clsTdBooked{
background-color: green;
}
.clsTdNotBooked{
background-color: white;
}
</Style>
</head>
<body>
<script type="text/javascript">
function insCell()
{
MyTable = document.getElementById("MyTableId");
MyTableRows = MyTable.getElementsByTagName("tr");
var MyCell;
for (var n = 1; n < MyTableRows.length; n++)
{
MyCell = MyTableRows[n].insertCell(4);
MyCell.innerHTML = "Min nya cell!";
}
}
</script>
<%
Connection connection = null;
Statement stmt = null;
ResultSet rs = null;
Statement stmt1 = null;
ResultSet rs1 = null;
try {
Class.forName("com.mysql.jdbc.Driver");
String url = "jdbc:mysql://localhost/frisor?user=root&password=feyte";
// ----------------------------------------------------------------------
// Hämta alla frisörer.
//----------------------------------------------------------------------
String query = "SELECT * FROM hairdresser";
connection = DriverManager.getConnection(url);
stmt = connection.createStatement();
rs = stmt.executeQuery(query);
out.println("<center>");
out.println("<Table id=MyTableId name='myTable' border='1' width=600>");
out.println("<tr>"); out.println("<td>Tid</Td>");
while (rs.next()){
String namn=rs.getString("firstname")+" "+rs.getString("surname");
out.println("<th>"+namn +"</th>");
}
out.println("</tr>");
stmt.close();
// ----------------------------------------------------------------------
// Loopar igenom timmar.
//----------------------------------------------------------------------
String strHour = "";
String strMinute="";
for (int intHour = 8; intHour < 18; intHour = intHour + 1){
if (intHour < 10){
strHour = "0"+intHour;
} else {
strHour = Integer.toString(intHour);
}
for (int intMinute = 0; intMinute <= 45; intMinute = intMinute + 15){
if (intMinute < 10){
strMinute = "0"+intMinute;
} else {
strMinute = Integer.toString(intMinute);
}
String tid=strHour+"."+strMinute;
// ----------------------------------------------------------------------
// Skriv dagens bokningar för frisörer
//----------------------------------------------------------------------
String query1 = "SELECT booking.starttime,booking.endtime,hairdresser.hairdresserid,"+
"hairdresser.firstname,hairdresser.color FROM booking "+
"INNER JOIN hairdresser ON hairdresser.hairdresserid=booking.hairdresserid "+
"WHERE booking.datum='2008-04-11'";
connection = DriverManager.getConnection(url);
stmt1 = connection.createStatement();
rs1 = stmt1.executeQuery(query1);
if (rs1.first()) {
rs1.beforeFirst();
out.println("<tr>");
out.println("<td>"+tid+"</td>");
while (rs1.next()){
//Här vill jag skriva ut bokningar till rätt person, allstå html-tabellen
out.println("<td>"+rs1.getString("starttime")+"</td>");
}
}
stmt1.close();
}
}
out.println("</tr>");
out.println("</Table>");
out.println("</center>");
}
catch (ClassNotFoundException e) {
out.println("Could not load database driver!");
}
catch (SQLException e) {
out.println("Could not connect to the database!");
}
finally
{ try{if(connection != null)connection.close(); }
catch(SQLException e){ }
}
%>
</body>
</html>