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);}?>
/>