Hopefully someone can help me out with this one.
I basically have some SQL returning results of a search page, where you can search on various keywords by checking boxes, and it returns Employers that match those keywords :
The results are drawing fields from the Employers table and EmployerContacts table, hopefully to look like :Code:mysql_select_db($database_myDatabase, $myDatabase); if (isset($_GET['ckbox'])){ // get profile keys $ckbox = array_keys($_GET['ckbox']); // sql string $sql = 'SELECT Employers.*, EmployerContacts.* FROM EmployerContacts INNER JOIN Employers ON EmployerContacts.EmployerID = Employers.EmployerID INNER JOIN EmployerProfiles ON EmployerProfiles.EmployerID = EmployerContacts.EmployerID WHERE EmployerProfiles.ProfileID IN(' . implode(',', $ckbox).') GROUP BY Employers.EmployerID ORDER BY Employers.EmployerID DESC'; $rsContacts = mysql_query($sql) or die(mysql_error()); $row_rsContacts = mysql_fetch_assoc($rsContacts); @$totalRows = mysql_num_rows($rsContacts); } else { echo 'You did not check any profiles.'; } ?>
Employer1
Employer1.Contact 1
Employer1.Contact 2
Employer1.Contact 3
Employer2
Employer2.Contact 1
Employer2.Contact 2
Employer2.Contact 3
etc
However, I can only seem to get it to repeat the Employers, and show just the first Contact for each, like this :
Employer1
Employer1.Contact 1
Employer2
Employer2.Contact 1
etc
So I guess I'm looking for help with looping through the Contacts for each Employer.
The code currently looks like this :
Hope that makes sense.Code:<form action="" method="post"> <table width="80%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td colspan="3" class="employerheader">Employer / Contacts</td> </tr> <?php // RepeatSelectionCounter_1 Begin Loop $RepeatSelectionCounter_1_IterationsRemaining = $RepeatSelectionCounter_1_Iterations; while($RepeatSelectionCounter_1_IterationsRemaining--){ if($RepeatSelectionCounterBasedLooping_1 || $row_rsContacts){ ?> <tr> <td class="employercell" colspan="2"><?php echo $row_rsContacts['Employer']; ?></td> <td width="61" class="employercell">Email ?</td> </tr> <tr> <td class="fieldcell"><?php echo $row_rsContacts['FirstName']; ?> <?php echo $row_rsContacts['LastName']; ?></td> <td width="302" class="fieldcell"><?php echo $row_rsContacts['JobTitle']; ?></td> <td width="61"><input name="EmailList_<?php echo $RepeatSelectionCounter_1; ?>" type="checkbox" id="EmailList_<?php echo $RepeatSelectionCounter_1; ?>" value="Y" <?php if (!(strcmp($row_rsContacts['EmailList'],"Y"))) {echo "checked=\"checked\"";} ?> /> <script type="text/javascript"> check_box[boxes] = "EmailList_<?php echo $RepeatSelectionCounter_1; ?>"; boxes += 1; </script></td> </tr> <?php } // RepeatSelectionCounter_1 Begin Alternate Content else{ ?> <?php } // RepeatSelectionCounter_1 End Alternate Content if(!$RepeatSelectionCounterBasedLooping_1 && $RepeatSelectionCounter_1_IterationsRemaining != 0){ if(!$row_rsContacts && $RepeatSelectionCounter_1_Iterations == -1){$RepeatSelectionCounter_1_IterationsRemaining = 0;} $row_rsContacts = mysql_fetch_assoc($rsContacts); } $RepeatSelectionCounter_1++; } // RepeatSelectionCounter_1 End Loop ?> <tr> <td colspan="3"> </td> </tr> <tr> <td colspan="3"><input name="Update Contacts" type="submit" value="Compose Email..." /> <input type="button" name="uncheck" value="Clear All Checkboxes" id="uncheck" onClick="uncheck_all(boxes, check_box);" /></td> </tr> </table> </form>
Many thanks.









Bookmarks