Este codigo muestra los viajes de un usuario.. y crea dos botones uno da la posibilidad de Modificar y otro la de Eliminar dicho viaje. El tema es que sin darle al boton Eliminar todos sus viajes se borran, si todos( ya que está dentro de un bucle while) Antes de eliminarse se supone deberia pulsar el boton Eliminar y despues Confirmar que deseas borrarlo... Pero sin ninguna de estas dos acciones, todas los viajes de un usuario se Borran.
Espero puedan ayudarme. Gracias y un saludo.
<?php
$sql="SELECT * FROM viajes WHERE ID = '".$_SESSION['idu']."' ORDER BY FECHA DESC";
// echo $sql;
$res = mysql_query($sql) or die (mysql_error());
?>
<table class="table" width="560" border="1" align="left" cellpadding="5" cellspacing="0">
<tr>
<td width="160">Origen</td>
<td width="160">Destino</td>
<td width="80">Fecha Viaje</td>
<td width="80">Modificar</td>
<td width="80">Eliminar</td>
</tr>
<?php
if(mysql_num_rows($res)>0){
while($r=mysql_fetch_assoc($res))
{
$qmuni_o=mysql_query("SELECT municipio FROM municipios WHERE idm='".$r['ORIGEN']."'");
$name_muni_o=mysql_fetch_assoc($qmuni_o);
$qmuni_d=mysql_query("SELECT municipio FROM municipios WHERE idm='".$r['DESTINO']."'");
$name_muni_d=mysql_fetch_assoc($qmuni_d);
$s=mysql_query("SELECT NOMBRE FROM usuarios WHERE ID='".$r['ID']."'");
$name_us=mysql_fetch_assoc($s);
?> <tr>
<td><?php echo $name_muni_o['municipio'];?></td>
<td><?php echo $name_muni_d['municipio'];?></td>
<td><?php echo date("d/m/Y", strtotime($r['FECHA']));?></td>
<td><button value="Modificar" onclick="parent.location.href='modificarviaje.php?IDV=<? echo $r['IDV'];?>'">Modificar</button></td>
<td><button value="Eliminar" onclick="if(confirm('¿Desea eliminar este viaje?'))
{ <?php $sql=mysql_query("DELETE FROM viajes WHERE IDV='". $r['IDV']."'"); ?>
parent.location='misviajes.php';
}">Eliminar</button></td>
</tr>
<?php }
}else{
?> <tr>
<td colspan="7"> <?php echo "No se obtuvieron resultados.. " ?> </td>
</tr>
<?php } ?>
</table>
Espero puedan ayudarme. Gracias y un saludo.
<?php
$sql="SELECT * FROM viajes WHERE ID = '".$_SESSION['idu']."' ORDER BY FECHA DESC";
// echo $sql;
$res = mysql_query($sql) or die (mysql_error());
?>
<table class="table" width="560" border="1" align="left" cellpadding="5" cellspacing="0">
<tr>
<td width="160">Origen</td>
<td width="160">Destino</td>
<td width="80">Fecha Viaje</td>
<td width="80">Modificar</td>
<td width="80">Eliminar</td>
</tr>
<?php
if(mysql_num_rows($res)>0){
while($r=mysql_fetch_assoc($res))
{
$qmuni_o=mysql_query("SELECT municipio FROM municipios WHERE idm='".$r['ORIGEN']."'");
$name_muni_o=mysql_fetch_assoc($qmuni_o);
$qmuni_d=mysql_query("SELECT municipio FROM municipios WHERE idm='".$r['DESTINO']."'");
$name_muni_d=mysql_fetch_assoc($qmuni_d);
$s=mysql_query("SELECT NOMBRE FROM usuarios WHERE ID='".$r['ID']."'");
$name_us=mysql_fetch_assoc($s);
?> <tr>
<td><?php echo $name_muni_o['municipio'];?></td>
<td><?php echo $name_muni_d['municipio'];?></td>
<td><?php echo date("d/m/Y", strtotime($r['FECHA']));?></td>
<td><button value="Modificar" onclick="parent.location.href='modificarviaje.php?IDV=<? echo $r['IDV'];?>'">Modificar</button></td>
<td><button value="Eliminar" onclick="if(confirm('¿Desea eliminar este viaje?'))
{ <?php $sql=mysql_query("DELETE FROM viajes WHERE IDV='". $r['IDV']."'"); ?>
parent.location='misviajes.php';
}">Eliminar</button></td>
</tr>
<?php }
}else{
?> <tr>
<td colspan="7"> <?php echo "No se obtuvieron resultados.. " ?> </td>
</tr>
<?php } ?>
</table>