Is there a problem with this code?

Source: Internet
Author: User
Is there a problem with this code? function getCategoryMapSelectly ($ tbl, $ cid ){
Global $ DB;
$ Return = '';
$ Ii = 1;
$ Arr = explode (',', $ cid );

Foreach ($ arr as $ k =>$ v ){
If (! $ V)
Unset ($ arr [$ k]);
}
Foreach ($ arr as $ value ){
$ Newarr [] = $ value;
}
For ($ I = 0; $ I
$ Arr_cat = $ DB-> get_result_array ($ tbl, '*', "WHERE id = '$ newarr [$ I]'");
Print_r ($ newarr );
}
Foreach ($ arr_cat as $ arr ){
$ Return. =' '. $ Arr ['title'].'';
$ Ii ++;
}
Return $ return;
}


Reply to discussion (solution)

$ Ii seems meaningless

No syntax error
Let's talk about your problem.

1. the first three cycles can be merged into one;
2. in the third loop, $ arr_cat is always assigned a value, instead of appending data. as a result, only the last data in the last loop is obtained;
3. I guess you want to pull down the data, that is, the option label instead of the select label.

No syntax error
Let's talk about your problem.


This method is used to split the value obtained from the left into groups and display a new array to the right.
The array on the left displays 1, 2, 3, 4, and click add to add 3, 2, 4, and 1.
However, if this method is not used, the value cannot be displayed.

1. the first three cycles can be merged into one;
2. in the third loop, $ arr_cat is always assigned a value, instead of appending data. as a result, only the last data in the last loop is obtained;
3. I guess you want to pull down the data, that is, the option label instead of the select label.


Yes. The data is to be pulled down.
I didn't pay attention to it. now I changed it to option. that's the second question you mentioned.

1. the first three cycles can be merged into one;
2. in the third loop, $ arr_cat is always assigned a value, instead of appending data. as a result, only the last data in the last loop is obtained;
3. I guess you want to pull down the data, that is, the option label instead of the select label.



This is the problem. The right side should be in the first position, but now it is in the last position.

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.