msaz87 Posted September 1, 2011 Share Posted September 1, 2011 Hey all, I'm trying to eliminate a spot where I used a query within another query's loop, but to do so I'm a little lost on creating the combo query. The current setup is as follows: <?php $results_query = mysql_query(" SELECT submission_id FROM reg_form_$form_id ORDER BY submission_id ASC") or die(mysql_error()); while($row = mysql_fetch_array($results_query)) { $submission_id = $row['submission_id']; ?> <tr> <?php foreach($fields as $col_name) { ?> <?php $data_query = mysql_query(" SELECT $col_name FROM reg_form_$form_id WHERE submission_id = '$submission_id'") or die(mysql_error()); while($row = mysql_fetch_array($data_query)) { $data = stripslashes($row[$col_name]); ?> <td><?php echo $data ?></td> <?php } ?> </tr> <?php } ?> The $fields variable is defined earlier and specifies what columns of the database it's supposed to pull, so the first query pulls the individual submission ID, then the second one pulls all the corresponding data for said ID. Any help combining these would be greatly appreciated... thanks in advance Quote Link to comment Share on other sites More sharing options...
msaz87 Posted September 1, 2011 Author Share Posted September 1, 2011 Figured it out.. $results_fields = join(", ",$fields); $results_query = mysql_query(" SELECT $results_fields FROM reg_form_$form_id WHERE submission_id IN ( SELECT submission_id FROM reg_form_$form_id ORDER BY submission_id ASC)") or die(mysql_error()); while($row = mysql_fetch_array($results_query)) { Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.