According to the conditions of the cycle of the box, please friends help me to see how you should change

Source: Internet
Author: User
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
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.