
Cosulta Campos Misma Tabla.
Publicado por Cristian (2 intervenciones) el 14/05/2014 22:00:59
Buenas tardes amigos, mi consulta es simple y concreta.
Tengo una tabla
RESERVAS (id, rut_empresario, rut_usuario, fecha, hora, estado)
Quiero registrar la reserva siempre y cuando:
-Rut_usuario no pueda registrar 2 o más reservas el mismo dia a la misma hora con
el mismo empresario.
- Que otro usuario no pueda registrar una reserva registrada con determinado
empresario.
Dato: El id se genera solo (random)., rut_empresario y usuario son claves foraneas.
T
Tengo una tabla
RESERVAS (id, rut_empresario, rut_usuario, fecha, hora, estado)
Quiero registrar la reserva siempre y cuando:
-Rut_usuario no pueda registrar 2 o más reservas el mismo dia a la misma hora con
el mismo empresario.
- Que otro usuario no pueda registrar una reserva registrada con determinado
empresario.
Dato: El id se genera solo (random)., rut_empresario y usuario son claves foraneas.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
A<?php
include "priv_admin.php";
include "conexion.php";
require "sqlvalue.php";
$editFormAction = $_SERVER['PHP_SELF'];
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "Registrar"))
{
$result=mysql_query("select rut_empresario, rut_usuario, fecha, hora, estado from reserva
where fecha='$_REQUEST[fecha]' and hora='$_REQUEST[hora]' ") or die(mysql_error());
if($row=mysql_fetch_array($result,MYSQL_BOTH))
{
echo '<script language="JavaScript">';
echo 'alert("La reserva no esta disponible.");';
echo 'window.location=("reserva.php");';
echo '</script>';
}
if($row[4]=="reservado")
{
echo '<script language="JavaScript">';
echo 'alert("La reserva no esta disponible.");';
echo 'window.location=("reserva.php");';
echo '</script>';
}
else{
srand(time()); $id_reserva=NULL;
for ($i=0; $i<6; $i++)
$id_reserva .= dechex(rand(0,15));
$flag=0;
$query="select id_reserva from reserva";
$result=mysql_query($query) or die(mysql_error());
while($row=mysql_fetch_array($result,MYSQL_BOTH))
{
if($row[0]==$id_reserva)
{
$flag=1; break;
}
}
$insertSQL = sprintf("insert into reserva values (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($id_reserva, "text"),
GetSQLValueString($_POST['rut_usuario'], "text"),
GetSQLValueString($_POST['rut_empresario'], "text"),
GetSQLValueString($_POST['fecha'], "text"),
GetSQLValueString($_POST['hora'], "text"),
GetSQLValueString(strtolower($_POST['estado']),"text"));
$result = mysql_query($insertSQL) or die(mysql_error());
//$updateSQL = sprintf("update inmueble set id_ven=%s where rol_ava=%s",
// GetSQLValueString($idVen, "text"),
// GetSQLValueString(strtoupper($_POST['rol_ava']), "text"));
// mysql_query($updateSQL) or die(mysql_error());
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<link href="../css/style_sys.css" rel="stylesheet" type="text/css" />
<SCRIPT LANGUAGE="JavaScript" SRC="../js/valida.js"></script>
</head>
<body>
<div>
<form action="<?php echo $editFormAction; ?>" method="post" name="Login" id="Login">
<fieldset>
<legend><b>CONSULTORIA REGISTRO</b></legend>
<p></p>
<table width="600" border="0" align="center">
<tr>
<td>Empresario:</td>
<td>
<select name="rut_empresario" required="required" title="Debe seleccionar Empresario">
<option></option>
<?php
$sql="select rut_empresario,nombre,ap_pat from empresario order by ap_pat";
$rec=mysql_query($sql);
while($row=mysql_fetch_array($rec))
{
echo '<option value="'.$row[0].'">';
echo ucwords($row[1]).' '.ucfirst($row[2]);
echo "</option>";
}
?>
</select>
</td>
<td>Fecha</td>
<td><input type="date" name="fecha" required="true" maxlength="1024"></td>
</tr>
<tr>
<td>Hora:</td>
<td>
<SELECT name="hora" required="required" title="Debe seleccionar hora">
<option></option>
<OPTION VALUE="08:30 - 10:00">08:30 - 10:00</OPTION>
<OPTION VALUE="10:30 - 12:00">10:30 - 12:00</OPTION>
<OPTION VALUE="12:30 - 14:00">12:30 - 14:00</OPTION>
<OPTION VALUE="14:30 - 16:00">14:30 - 16:00</OPTION>
</SELECT>
</td>
<?php
$rut_usuario=$_SESSION["rutusu"];
$query_DatosUsuario = "select * from usuario" ;
$DatosUsuario = mysql_query($query_DatosUsuario) or die(mysql_error());
$row_DatosUsuario = mysql_fetch_array($DatosUsuario);
$totalRows_DatosUsuario = mysql_num_rows($DatosUsuario);
?>
<td>Su Rut:</td>
<td><input type="text" name="rut_usuario" value="<?php echo $rut_usuario ?>" required="true" maxlength="1024" readonly></td>
</tr>
<td></td>
<td>
<SELECT name="estado" required="true" style="visibility:hidden">
<OPTION VALUE="reservado">Reservado</OPTION>
</SELECT>
</td>
</tr>
<tr align="center" >
<td COLSPAN=4 valign="top">
</p><p>
<input type="submit" name="MM_insert" value="Registrar" class="button button-pill button-action button-tiny">
<input type="reset" value="Borrar" class="button button-pill button-caution button-tiny">
</td>
</tr>
</table>
</fieldset>
</form>
</div>
</body>
</html>
T
Valora esta pregunta


0