Forum Moderators: coopster
I have the following query:
$query_flag = "SELECT DISTINCT `candidate_id` , `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."'";
$result_flag = mysql_query($query_flag, $db_connect);
Thanks for any help in advance
If there are no rows - you can check with mysql_num_rows($result_flag) - then move on to the next color.
Alternatively you could get all of the note status codes for the candidate:
$query_flag = "SELECT `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."'";
use one of the mysql_fetch_ functions to put the rows into an array and use in_array [us3.php.net] for each of the colors in turn:
if(in_array('red',$status_array)) {
}
elseif(in_array('orange'. . .
i have basically got it working, but it is really messy and would prefer it to be not as ugly as it is :-P
here is what ive got so far. is there a better way of writing this to produce the same outcome?
$query_flag = "SELECT `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."' AND status='red'";
$result_flag = mysql_query($query_flag, $db_connect);
if(mysql_num_rows($result_flag)>0){
$flag="red";
}else{
$query_flag2 = "SELECT `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."' AND status='orange'";
$result_flag2 = mysql_query($query_flag2, $db_connect);
if(mysql_num_rows($result_flag2)>0){
$flag="orange";
}else{
$query_flag3 = "SELECT `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."' AND status='green'";
$result_flag3 = mysql_query($query_flag3, $db_connect);
if(mysql_num_rows($result_flag3)>0){
$flag="green";
}
}
}
$query_flag = "SELECT `status` FROM `notes` WHERE `candidate_id` ='".$candidate_item['id']."'";
$result_flag = mysql_query($query_flag, $db_connect);
while($rows[] = mysql_fetch_row($result_flag));
if(in_array('red',$rows))
$flag='red';
elseif(in_array('orange',$rows))
$flag='orange';
elseif(in_array('green',$rows))
$flag='green';