Hi there in my database I have 3 columns, is_contract, is_permenant and is_temporary. Within these columns there is either a Y or N value.
I am using these columns to echo onto the page what kind of work someone is looking for, my problem is that the user can be looking for more than one type of work, I am currently running 3 if statements to determine what to echo to the page, however I am struggling to add a comma if more than one of the statemnts returns as true, below is my code so far,
<?php
if($rslt['is_contract'] == 'Y') {
echo "Contract ";
}
if($rslt['is_permanent'] == 'Y') {
echo "Permanent ";
}
if($rslt开发者_如何学编程['is_temporary'] == 'Y') {
echo "Temporary";
}
?>
<?php
$out=array();
if($rslt['is_contract'] == 'Y') $out[]="Contract";
if($rslt['is_permanent'] == 'Y') $out[]="Permanent";
if($rslt['is_temporary'] == 'Y') $out[]="Temporary";
echo implode(", ",$out);
?>
Either you can use like this in simple way
if($rslt['is_contract'] == 'Y') {
echo "Contract ";
}
if($rslt['is_permanent'] == 'Y') {
if($rslt['is_contract'] == 'Y') {
echo ", ";
}
echo "Permanent ";
if($rslt['is_temporary'] == 'Y') {
echo ", ";
}
}
if($rslt['is_temporary'] == 'Y') {
if($rslt['is_contract'] == 'Y' && $rslt['is_permanent'] != 'Y') {
echo ", ";
}
echo "Temporary";
}
精彩评论