0

Would doing an INNER JOIN or LEFT JOIN or RIGHT JOIN work better for this? Or is there a better way to do this?

$customSQL = "SELECT * FROM customFieldNames"; $customQRY = mysql_query($customSQL); while ($customOBJ = mysql_fetch_object($customQRY)){ $cvSQL = "SELECT `VALUE` FROM customFieldValues WHERE FIELDID = '".$customOBJ->FIELDID."' AND MEMID = '".$memFetch['MEMID']."'"; $cvQRY = mysql_query($cvSQL); $cvFetch = mysql_fetch_array($cvQRY); echo '<tr><td>'.$customOBJ->FIELDNAME.'</td><td><input type="text" name="cv_'.$customOBJ->FIELDNAME.'" value="'.$cvFetch['VALUE'].'" /></td></tr>'; } 
1
  • 1
    Please consider adding a description, in words, of what you're trying to achieve, rather than forcing us to interpret the code and infer your intentions. This will lead to better answers. Further, it would help to have a look at your schema; where does "MEMID" come from? Thanks! Commented Nov 28, 2011 at 0:58

2 Answers 2

1

Yes, something of this kind

 //this is just a sample to let you know how it can be select c1.somefield, c2.somefield from customFieldNames c1 left join customFieldValues c2 on(c1.somefieldId = c2.somefildId) where 1=1 
Sign up to request clarification or add additional context in comments.

Comments

0

Your current code is equivalent to performing an INNER JOIN, in that it won't print anything unless there's a match between the two tables. Specifically, it's equivalent to this INNER JOIN:

SELECT customFieldNames.FIELDNAME, customFieldValues.VALUE FROM customFieldNames JOIN customFieldValues ON customFieldNames.FIELDID = customFieldValues.FIELDID WHERE customFieldValues.MEMID = ... 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.