error while updating

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

error while updating

Post by hrubos »

Why doesn't my command run ???

Code: Select all

if(mysql_num_rows($result_query)>0){
$rc_student = "";
$s = $_SESSION['valid_idReser'];
//return room which will be deleted
$room_del="Select r.id_numberRoom FROM reservation r, room p WHERE r.id_reservation='$s'";
$result_room=mysql_query($room_del);

$num=mysql_numrows($result_room);
$i=0;
while ($i<$num){
	$id_numberRoom=mysql_result($result_room,$i,"id_numberRoom");
       $state_room = "UPDATE room SET state_room = 'volný'
                  WHERE id_numberRoom = '$id_numberRoom' ";
  mysql_query($state_room);
  
  $i++;
}
if I tried

Code: Select all

if(mysql_num_rows($result_query)>0){
$rc_student = "";
$s = $_SESSION['valid_idReser'];
//return room which will be deleted
$room_del="Select r.id_numberRoom FROM reservation r, room p WHERE r.id_reservation='$s'";
$result_room=mysql_query($room_del);

$num=mysql_numrows($result_room);
$i=0;
while ($i<$num){
	$id_numberRoom=mysql_result($result_room,$i,"id_numberRoom");
	echo 	$id_numberRoom;
  
  $i++;
}
,
output is more than 1 result -> output : 1818181818181818. but I only need : 18
Corvin
Forum Commoner
Posts: 49
Joined: Sun Dec 03, 2006 1:04 pm

Post by Corvin »

Remove the while loop (not the code it contains) and use DISTINCT to optimize your query.
hrubos
Forum Contributor
Posts: 172
Joined: Sat Oct 07, 2006 3:44 pm

Post by hrubos »

Corvin wrote:Remove the while loop (not the code it contains) and use DISTINCT to optimize your query.
oh la la la, it runs , thank much . :)
Happy new year !!!
Post Reply