I am trying to create a SELECT statement that requires multiple WHERE conditions. Is that possible. Here is the scenario. I have a table with the following structure.
FormID (Type Int)
SubmissionID (Type Int)
FieldName (Type text)
FieldValue (Type text)
The data would be something like this. Table Name: SubmissionsValue
FormID - SubmissionID - FieldName - FieldValue 24 ------ 5 ---------- username ------ johnk 24 ------ 5 ---------- firstname ------ John 24 ------ 5 ---------- lastname ------ King 24 ------ 5 ---------- address ------ 100 some street 24 ------ 5 ---------- email ------ johnemail@gma.com 24 ------ 9 ---------- username ------ cathym 24 ------ 9 ---------- firstname ------ Catherine 24 ------ 9 ---------- lastname ------ Mirusia 24 ------ 9 ---------- address ------ 100 some other street 24 ------ 9 ---------- email ------ cathyemail@gma.com 32 ------ 20 ---------- username ------ johnk 32 ------ 20 ---------- firstname ------ John 32 ------ 20 ---------- lastname ------ King 32 ------ 20 ---------- address ------ 100 some street 32 ------ 20 ---------- email ------ johnemail@gma.com 32 ------ 20 ---------- AdultTicket------ 5 32 ------ 20 ---------- SingleTicket------ 3 32 ------ 20 ---------- Total ------ $60.00
Apparently this is an Entity-Attribute-Value (EAV) design, I have been told!
As you can see the "FieldName", "FieldValue" etc are the actual names of the Fields of the table. Also entries from multiple forms from a same user can appear in the table. So my keyfield are the user emailID and the formID.
Then fieldnames are stored in the table along with it's fieldvalue for each online form.
Therefore "username", "firstname", "lastname", "address" and "email" are the actual fields in form and when the User submit their information, it gets stored in the table as shown above.
I want to show the details of the User in another area using their emailID as the key field.
Essentially this is what has to happen ($user->email gives the email of the current User):
SELECT username WHERE (FieldName = "email") AND (FieldValue = " $user->email")
But in reality to get the values "johnk" and "cathym" in my example, what it seems that I have to do is the following but I am not sure how to code that:
SELECT FieldValue WHERE (FieldName = "username")
(WHERE (FieldName = "email")
AND (FieldValue = " $user->email"))
Can someone please help me with this scripting?
This is for a Joomla site using RSForm!Pro. RSForm!Pro stores the form input in the above manner!!!
=== EDIT ====
Clarification: The table data shown above is all from one table. I just added a space between the two sets of data for readability.
You can essentially ignore FormID and SubmissionID. The backend keeps the entries from various different forms all in one table and therefore, it tracks the formID and the submissionID. So you can see that there will be various formID and submissionID in that table, eventually.
In this example, the data was entered from the same form, but two different submissions - 5 & 8.
In this case, I simply want to autopopulate the fields of a new form with the information of the User who is logged in.
Last Name: John King
User Address: 100 Some Street
etc...