ellegua220 Posted March 10, 2011 Share Posted March 10, 2011 In php and sql how can i use multiple tables to populate a form for updating user information? Here is a simplified table structure: user userid PK first_name last_name parent parent_id PK parent_first_name parent_last name parent_user parent_user_id PK parent_id FK userid FK Here is what I have tried. I need to use the new table parent and parent_user to populate parent_first_name and parent_last_name. I think i need to JOIN the info in the select statement: Here is the select statement I was trying to use but its not working: $query = "SELECT user.userid, user.username, user.email, user.first_name, user.last_name, user.password, user.phone, user.street_address, user.other_address, city, state, zipcode, type, school, school_district, DATE_ADD(user.date_registered, INTERVAL $time_diff HOUR),user.double_gui,user.status_id,use… parent.parent_first_name from user, parent_user, parent where user.userid=$userid and parent_user.userid=$userid and parent.parent_id=$userid"; this is the original code that just uses the user table: query = "SELECT userid, username, email, first_name, last_name, password, phone, street_address, other_address, city, state, zipcode, type, school, school_district, DATE_ADD(date_registered, INTERVAL $time_diff HOUR),double_gui,status_id,notes from user where userid=$userid"; $result = mysql_query($query, $mysql_link); if((!result) || (! mysql_num_rows($result))) { die("<p class=highlight>error getting details of user userid=$userid from db</p>"); } if ($row = mysql_fetch_row($result)) { $userid = $row[0]; $username = $row[1]; $email = $row[2]; $first_name = $row[3]; $last_name = $row[4]; //$parent_last_name = $row[5]; $password = $row[5]; // no it didn't print "<tr><td> will this print next to the password??????</td></tr>"; $phone = $row[6]; $street_address = $row[7]; $other_address = $row[8]; $city = $row[9]; $state = $row[10]; $zipcode = $row[11]; $type = $row[12]; $school = $row[13]; $school_district = $row[14]; $date_registered = $row[15]; $double_gui = $row[16]; $status_id = $row[17]; $notes = $row[18]; if ($type == "S") { $student_selected = "selected"; } elseif ($type == "T") { $tutor_selected = "selected"; } elseif ($type == "A") { $admin_selected = "selected"; } elseif ($type == "K") { $tech_selected = "selected"; } } } print "<form>"; print "<table>"; if ($action == "edit") { print "<input type=hidden name=action value=update>"; print "<input type=hidden name=userid value='$userid'>"; } else { print "<input type=hidden name=action value=insert>"; } // action is not edit then has to be add mp print "<tr><td>Username:</td><td><input type=text maxlength=40 name=username value=\"$username\"> (REQUIRED)</td><tr>"; print "<tr><td>Status:</td><td><select name=status_id><option value=\"\"></option>"; Link to comment https://forums.phpfreaks.com/topic/230152-help-with-woking-with-multiple-tables-for-populating-an-update-form-for-users/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.