Update varios registros de uma tabela com mesmo ID
Preciso fazer um update na tabela de varios campos que tem o mesmo ID, a tabela é essa:
--
-- Estrutura da Tabela Restaurante Horarios
--
CREATE TABLE restaurante_horarios(
id_restaurante_horario int(11) NOT NULL auto_increment,
id_restaurante int(11) NOT NULL,
id_restaurante_horario_semana int(11) NOT NULL,
hora_inicio time NOT NULL,
hora_final time NOT NULL,
data date NOT NULL,
data_mod date NOT NULL,
PRIMARY KEY(id_restaurante_horario),
INDEX i2 (id_restaurante, id_restaurante_horario_semana),
FOREIGN KEY (id_restaurante) REFERENCES restaurantes(id_restaurante) ON DELETE CASCADE,
FOREIGN KEY (id_restaurante_horario_semana) REFERENCES restaurante_horario_semanas(id_restaurante_horario_semana) ON DELETE CASCADE
) ENGINE = InnoDB;
-- --------------------------------------------------------
e na hora de editar mostra como o arquivo em anexo.
na hora de editar busco os dados do banco assim:
<?php
include "connection.php";
if(!isset($_POST["submit"])){
$id_restaurante = $_GET["id_restaurante"];
$sql = "SELECT restaurante_horarios.*, restaurante_horario_semanas.* FROM restaurante_horarios INNER JOIN restaurante_horario_semanas ON restaurante_horarios.id_restaurante_horario_semana = restaurante_horario_semanas.id_restaurante_horario_semana WHERE restaurante_horarios.id_restaurante = '$id_restaurante' ORDER BY restaurante_horario_semanas.id_restaurante_horario_semana ASC";
$resultado = mysql_query($sql) or die (mysql_error());
if(mysql_num_rows($resultado) < 1){
}
else{
echo "<form id=\"loading-button\" name=\"form\" action=\"timetable_update.php?id_restaurante=$id_restaurante\" method=\"post\">";
while($linha = mysql_fetch_array($resultado)){
$id_restaurante_horario = $linha["id_restaurante_horario"];
$id_restaurante_horario_semana = $linha["id_restaurante_horario_semana"];
$restaurante_horario_semana = $linha["restaurante_horario_semana"];
$hora_inicio = $linha["hora_inicio"];
$hora_final = $linha["hora_final"];
$novo_hora_inicio = date("H:i", strtotime($hora_inicio));
$novo_hora_final = date("H:i", strtotime($hora_final));
echo "<table class=\"layout-big\" width=\"800\">";
echo "<tr>";
echo "<td width=\"15%\">$restaurante_horario_semana</td>";
echo "<td width=\"30%\"> </td>";
echo "<td width=\"15%\"> </td>";
echo "<td width=\"30%\"> </td>";
echo "</tr>";
echo "<tr>";
echo "<td width=\"15%\">$timetable_time_first</td>";
echo "<td width=\"30%\"><input id=\"time_first\" class=\"input\" name=\"hora_inicio[]\" type=\"text\" size=\"35\" maxlength=\"5\" pattern=\"([01]?[0-9]|2[0-3]):[0-5][0-9]\" value=\"$novo_hora_inicio\" onkeyup=\"TimeFirst(this.value)\" onkeypress=\"return validNumb(event)\" required /></td>";
echo "<td width=\"15%\">$timetable_time_last</td>";
echo "<td width=\"30%\"><input id=\"time_last\" class=\"input\" name=\"hora_final[]\" type=\"text\" size=\"35\" maxlength=\"5\" pattern=\"([01]?[0-9]|2[0-3]):[0-5][0-9]\" value=\"$novo_hora_final\" onkeyup=\"TimeLast(this.value)\" onkeypress=\"return validNumb(event)\" required /></td>";
echo "</tr>";
echo "</table>";
echo "<br />";
}
}
echo "<table class=\"layout-big\" width=\"800\">";
echo "<tr>";
echo "<td width=\"10%\">$button_confirmation</td>";
echo "<td width=\"50%\"><input class=\"button\" name=\"submit\" type=\"submit\" value=\"$button_modify\" /></td>";
echo "</tr>";
echo "</table>";
echo "</form>";
}
?>
/monthly_2017_06/5938011fe30ab_Screenshot(145).png.15e34a51c746ad35d14dbd33f7d54310.png" class="ipsImage ipsImage_thumbnailed" alt="Screenshot (145).png">.png.15e34a51c746ad35d14dbd33f7d54310.png)
Discussão (6)
Carregando comentários...