PHP Programming Questions about multi-choice box selection by default

Source: Internet
Author: User
PHP programming about multi-choice box selected by default two tables sub_role_table (srt_id, id, role_id) id is the user id, role_id is the role idrole_table (role_id, role_name) role_name is the role name. now you need to modify multiple roles of a user.
Two tables
Sub_role_table (srt_id, id, role_id) id is the user id, and role_id is the role id
Role_table (role_id, role_name) role_name is the role name
Now we need to implement the modification of multiple roles of a user to cycle all roles on the modification page. then, what roles does the user have and what roles are selected by default?
The source code is as follows:
========================================================== ====================
$ SQL = "select * from role_table where role_id! = 0 ";
$ Re = mysql_query ($ SQL );

$ Sql2 = "select * from sub_role_table where id = '$ ID '";
$ Res = mysql_query ($ sql2 );

$ Showa = '';
While ($ row = mysql_fetch_array ($ res )){
While ($ roww = mysql_fetch_array ($ re )){
If ($ roww [role_id] = $ row [role_id]) {
$ Showa. =" $ Roww [role_name] ";
} Else {
$ Showa. ="
$ Roww [role_name] ";
}
}
}
Print_r ($ showa );
?>
When a user has multiple roles, only the first role of the user is selected by default. other roles are not selected by default, hope you guys can check the code error. let me select the default check box.

------ Solution --------------------
PHP code
  Error :". mysql_error (); if (mysql_affected_rows ()> 0) {$ allinfors = array (); while ($ rows = mysql_fetch_array ($ re) {array_push ($ allinfors, $ rows) ;}# modify the information $ sql2 = "select * from sub_role_table where id = '$ ID'"; $ res = mysql_query ($ sql2); if (! $ Re) die ("SQL: {$ SQL}
Error: ". mysql_error (); if (mysql_affected_rows ()> 0) {$ editinfor = mysql_fetch_array ($ res);}?> />

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.