According to the conditions of the cycle of the box, please friends help me to see how should be changed
$sql = "Select ' id ', ' name '
From ' interior_authority ';
$row [' Authorityid ']= "a,b,c,d,e";//This value is for easy viewing plus go, originally this value is read from the database.
$authority = Explode (",", $row [' Authorityid ']);
$row array $row[id] values are "a,b,c,d,e,f,c" respectively, and this value is also for easy viewing plus the original value is read from the database.
$sql = mysql_query ($sql, $conn);
while ($row = Mysql_fetch_array ($sql)) {
foreach ($authority as $value) {
if ($row [' id ']== $value) {
echo<<
<>
$row [Name]
EOD;
}
}
}
?>
The result I want is $row[' id ']== $value check box to "√", other unequal will be displayed directly!
Now the problem is that the check box can be "√", but those who did not hit "√" will not show, if in the Whiel loop add a
echo<<
<>
$row [Name]
EOD;
Then he would repeat the show;
I hope you guys can do me a favor. PHP based on condition loop display
Share to:
------Solution--------------------
foreach ($authority as $value) {
$checked = $row [' id ']== $value? ' Checked ': ';
echo<<
<>
$row [Name]
EOD;
}
------Solution--------------------
foreach ($mysqlResult as $row) {
$hasValue = false;
foreach ($authority as $value) {
if ($row [' id ']== $value) {
$hasValue = true;
}
}
if ($hasValue) {
echo ' yes ';
}else{
Echo ' no ';
}
}
For the time being only think of this method, I do not know if there is an improved version