According to the conditions of the cycle of the box, please friends help me to see how should be changed

Source: Internet
Author: User
PHP based on condition loop display

 
 
  $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.


Reply to discussion (solution)

foreach ($authority as $value) {  $checked = $row [' id ']== $value? ' Checked ': ';  echo<<
 <>
  $row [Name]eod;}
 

You only let the program show the same situation, and the program does not show unequal conditions.

if ($row [' id ']== $value) {            echo<<
 <>
  $row [Name]eod;         } else{echo<<
  <>
   $row [Name]eod;}
  
 

You only let the program show the same situation, and the program does not show unequal conditions.

if ($row [' id ']== $value) {            echo<<
 <>
  $row [Name]eod;         } else{echo<<
  <>
   $row [Name]eod;}
  
 
So that every time we iterate through the array, he repeats it, I tried.

if ($id = = $value) {}else{}
How can this be repeated?
On one condition, either or No.

if ($id = = $value) {}else{}
How can this be repeated?
On one condition, either or No.

Because there's a shield ring in there: the Foreach and while loops

While loop once, foreach loops 4 times because the $authority array has 4 values, only one value in these 4 values is configured with $id, and if you add else in if, then he will be in the same record 3 times if else value

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

Solve the problem, solve the code as follows, thank the enthusiastic friend reminds

 
 
  $row [Name]eod;break; }else{$pd = "false";} If End $cc = $cc. $cc;} foreach endif ($pd = = "true") {echo $cc;} Else{echo <<
 <>
  $row [Name]eod;}} ?>
 

Moderator of this method, not only will repeat the choice of the mouth will not come out, but still thank you for your Enthusiasm

  • 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.