php - How to return unknown value using known value from same column in SQL -
i have form submits email address, name , image plus few more fields. submissions stored in same column named sentvalue each form field's unique name in column formfield.
first time submissions require fields returning users need enter email , form returns image upload because found email address in db.
i want use known value of fieldname 'email' return it's matching 'name' value fieldname 'name' , print page image upload.
this without correct logic , have attempted numerous other formats , sql syntax
select sentvalue name tbl_submission formid='2' , formfield='name' , formfield='email' , sentvalue='smit@home.com' return $query;
what correct sql query achieve goal?
@matt structure
tbl_submission
formid - because multiple forms post table , each has id
formsubsid - each field's data gets id on db entry
formfield - stores unique name of each field
sentvalue - stores value of each field entered user
|formid|formsubsid|formfield|sentvalue| | 1 | 1 | name | mike | | 1 | 1 | email |mi@hom.us| | 1 | 1 | image |img.jpg | | 2 | 34 | image |new.jpg |
the first page user sees has form single email text field. entry not stored in db formid 1 in db queried on submission see if entered email exists. if not, form id 1 showing required fields returned.
if query returns true email in db, yet different form id 2 returned displays single image upload field , image stored in same sentvalue col. on page want name associated found email, printed.
if understand correctly, need find possible name same formsubsid email 'mi@hom.us'. can using simple left join, since name may possibly not exist;
select name.sentvalue name tbl_submission email left join tbl_submission name on email.formsubsid = name.formsubsid , name.formfield = 'name' email.formfield = 'email' , email.sentvalue = 'mi@hom.us'
this return name, or null if no name exists. if instead want no result @ if name doesn't exist, can change left join regular join.
Comments
Post a Comment