Daminious
04-19-2006, 11:15 PM
Hello, I have a problem. I am creating an administration area for a members only area of a website. Within this administration area I have pages deticated for specific functions, such as search members, create members, exc.
Right now I am working on the search members function. I want the admin to be able to search all members of the database for multiple fields. For example, I want the admin to have the choose to search for Username, User_ID, Area Code, Phone Number, City, State, exc. I store these values in their respected tables. I have created a form for the user to fill out. This form allows the user to input the fields they wish to search for. My problem is creating a query that allows for any of the data to be searched for that runs across multiple tables.
Table: Customer_Authorization
Primary Key: User_ID, Secret_Question_ID
Fields:
User_ID
Username
Password
E-Mail
Question_ID
Secret_Question_Answer
Member_Type
Created_Date
Modified_Date
Table: Customer_Information
Primary Key: Customer_Information_ID
Foreign Key: User_ID
Fields:
Customer_Information_ID
User_ID
First_Name
Last_Name
Created_Date
Modified_Date
Table: Address_Information
Primary Key: Address_Information_ID
Foreign Key: User_ID
Fields:
Address_Information_ID
User_ID
House_Number
Street
City
State
Zip
Created_Date
Modified_Date
Table: Phone_Information
Primary Key: Phome_Information_ID
Foreign Key: User_ID, Phone_Type_ID
Fields:
Phone_Information_ID
User_ID
Area_Code
Phone_Number
Phone_Type_ID
Created_Date
Modified_Date
Table: Phone_Type_Information
Primary Key: Phone_Type_ID
Fields:
Phone_Type_ID
Phone_Type_Description
Here is the form I am wanting to use to search for the above values:
<form action="admin_search.php" method="post" name="member_edit" id="member_edit">
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">User ID:</td>
<td width="72%"><input name="User_ID" type="text" id="User_ID" size="15" maxlength="100" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input name="Username" type="text" id="Username" size="30" maxlength="86" /></td>
</tr>
</table>
<br />
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">First Name:</td>
<td width="72%"><input name="First_Name" type="text" id="First_Name" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input name="Last_Name" type="text" id="Last_Name" size="30" maxlength="86" /></td>
</tr>
<tr>
<td>E-Mail Address: </td>
<td><input name="EMail" type="text" id="EMail" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Phone Number: </td>
<td><input name="Area_Code" type="text" id="Area_Code" size="3" maxlength="3" />
-
<input name="Phone_Number" type="text" id="Phone_Number" size="7" maxlength="7" /></td>
</tr>
<tr>
<td>Birthday (YYYY/MM/DD):</td>
<td><input name="Birthday_Year" type="text" id="Birthday_Year" size="4" maxlength="4" />
-
<input name="Birthday_Month" type="text" id="Birthday_Month" size="2" maxlength="2" />
-
<input name="Birthday_Day" type="text" id="Birthday_Day" size="2" maxlength="2" /></td>
</tr>
</table>
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">House Number:</td>
<td width="72%"><input name="House_Number" type="text" id="House_Number" size="5" maxlength="5" /></td>
</tr>
<tr>
<td>Street:</td>
<td><input name="Street" type="text" id="Street" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>City: </td>
<td><input name="City" type="text" id="City" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>State: </td>
<td><input name="State_Menu" type="text" id="State_Menu" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Zip:</td>
<td><input name="Zip" type="text" id="Zip" size="5" maxlength="5" /></td>
</tr>
</table>
<br />
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td><input name="submitok" type="submit" id="submitok" value="Search Members Database" /></td>
</tr>
</table>
</form>
My questions is, how do I write a query that will search the above tables for the information submitted in the form, being the information is contained in multiple tables? I am reading about unions, but they are not working for me. I am also reading about joins, but how do I write a join from dynamic data?
I am using MYSQL version 5.0.19, and I am using PHP 5.1.2 to access the data. Thanks.
Daminious
Right now I am working on the search members function. I want the admin to be able to search all members of the database for multiple fields. For example, I want the admin to have the choose to search for Username, User_ID, Area Code, Phone Number, City, State, exc. I store these values in their respected tables. I have created a form for the user to fill out. This form allows the user to input the fields they wish to search for. My problem is creating a query that allows for any of the data to be searched for that runs across multiple tables.
Table: Customer_Authorization
Primary Key: User_ID, Secret_Question_ID
Fields:
User_ID
Username
Password
Question_ID
Secret_Question_Answer
Member_Type
Created_Date
Modified_Date
Table: Customer_Information
Primary Key: Customer_Information_ID
Foreign Key: User_ID
Fields:
Customer_Information_ID
User_ID
First_Name
Last_Name
Created_Date
Modified_Date
Table: Address_Information
Primary Key: Address_Information_ID
Foreign Key: User_ID
Fields:
Address_Information_ID
User_ID
House_Number
Street
City
State
Zip
Created_Date
Modified_Date
Table: Phone_Information
Primary Key: Phome_Information_ID
Foreign Key: User_ID, Phone_Type_ID
Fields:
Phone_Information_ID
User_ID
Area_Code
Phone_Number
Phone_Type_ID
Created_Date
Modified_Date
Table: Phone_Type_Information
Primary Key: Phone_Type_ID
Fields:
Phone_Type_ID
Phone_Type_Description
Here is the form I am wanting to use to search for the above values:
<form action="admin_search.php" method="post" name="member_edit" id="member_edit">
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">User ID:</td>
<td width="72%"><input name="User_ID" type="text" id="User_ID" size="15" maxlength="100" /></td>
</tr>
<tr>
<td>Username:</td>
<td><input name="Username" type="text" id="Username" size="30" maxlength="86" /></td>
</tr>
</table>
<br />
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">First Name:</td>
<td width="72%"><input name="First_Name" type="text" id="First_Name" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input name="Last_Name" type="text" id="Last_Name" size="30" maxlength="86" /></td>
</tr>
<tr>
<td>E-Mail Address: </td>
<td><input name="EMail" type="text" id="EMail" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>Phone Number: </td>
<td><input name="Area_Code" type="text" id="Area_Code" size="3" maxlength="3" />
-
<input name="Phone_Number" type="text" id="Phone_Number" size="7" maxlength="7" /></td>
</tr>
<tr>
<td>Birthday (YYYY/MM/DD):</td>
<td><input name="Birthday_Year" type="text" id="Birthday_Year" size="4" maxlength="4" />
-
<input name="Birthday_Month" type="text" id="Birthday_Month" size="2" maxlength="2" />
-
<input name="Birthday_Day" type="text" id="Birthday_Day" size="2" maxlength="2" /></td>
</tr>
</table>
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td width="28%">House Number:</td>
<td width="72%"><input name="House_Number" type="text" id="House_Number" size="5" maxlength="5" /></td>
</tr>
<tr>
<td>Street:</td>
<td><input name="Street" type="text" id="Street" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>City: </td>
<td><input name="City" type="text" id="City" size="30" maxlength="100" /></td>
</tr>
<tr>
<td>State: </td>
<td><input name="State_Menu" type="text" id="State_Menu" size="2" maxlength="2" /></td>
</tr>
<tr>
<td>Zip:</td>
<td><input name="Zip" type="text" id="Zip" size="5" maxlength="5" /></td>
</tr>
</table>
<br />
<br />
<table width="96%" border="0" align="center" cellpadding="1" cellspacing="1">
<tr>
<td><input name="submitok" type="submit" id="submitok" value="Search Members Database" /></td>
</tr>
</table>
</form>
My questions is, how do I write a query that will search the above tables for the information submitted in the form, being the information is contained in multiple tables? I am reading about unions, but they are not working for me. I am also reading about joins, but how do I write a join from dynamic data?
I am using MYSQL version 5.0.19, and I am using PHP 5.1.2 to access the data. Thanks.
Daminious