From what I can see your using if($result_loop) if(mysql_num_rows($result_loop) > 0) which you should not do instead use ||(OR), &&(AND) for multiple conditions in your if statements
$myVar = 1;
$gt = 0;
if ($myVar != "" AND $myVar > $gt)
echo "my variable is not blank and is greater than 0";
// both conditions were not met trigger error
echo "variable is either blank or is less than 0";
The above would say "my variable is not blank and is greater than 0". The reason is anytime you use either && or AND it will check to make sure both conditions are met and if they are not it will execute the code in the else or else if statement and if you have neither the code will terminate because not other conditions were added. If you use || or OR it will check to see if one of the conditions are met and if so execute the code but if none of the conditions are met it will move to the else if or else statements or terminate the process.