HDRebel88 Posted July 21, 2013 Share Posted July 21, 2013 (edited) On this page I have a bunch of contact information for each individual employee in the company:http://www.kamentertainment.net/contact Everything is grouped together properly except when a category has an odd number of employees. In this case the first employee for the next category is added to the previous category. How do I fix this, so that if a category only has three employees the fourth div cell in the group is generated with a blank div cell? if($staffQuery=mysqli_query($staffConnected, "SELECT `name`, `email`, `department`, `position` FROM `staff` WHERE `class`=2 ORDER BY `department`, `name` ASC")){ $rowNum=1; $cellNum=0; $amountOfStaffReturned=mysqli_num_rows($staffQuery); if($amountOfStaffReturned>0){ $departmentHeader=false; $content.='<div class="emailHeader">Staff Contacts</div>'; while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)){ $staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position']; $rowName=rowName($rowNum); if($rowNum>1){$rowEmailClassAdd=' emailRow';}else{$rowEmailClassAdd='';} if($cellNum%2==0){ if($departmentHeader!=$staffDepartment){$content.='<div class="departmentHeader">'.$staffDepartment.'</div>'; $departmentHeader=$staffDepartment;}else{} if($cellNum!=0){$content.='</div>';}else{} $content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">'; $rowNum++; }else{} $content.=' <div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; if(($amountOfStaffReturned%2!=0 && $cellNum+1==$amountOfStaffReturned)){ $content.='<div class="emailCell"> </div> </div>'; }else{} $cellNum++; } }else{} } Edited July 21, 2013 by HDRebel88 Quote Link to comment Share on other sites More sharing options...
HDRebel88 Posted July 21, 2013 Author Share Posted July 21, 2013 Just to clear things up a bit, the Assistants group should only have three employees in it, Information Technology should also have three (Dennis O'Neal) should be moved down to the IT group, the Post-Production group should have three, the Production group should have four, and the sales group should have three. Quote Link to comment Share on other sites More sharing options...
DarkSuperHero Posted July 22, 2013 Share Posted July 22, 2013 Your code is littered with extra empty else statements....try to make your code easier to read, it makes it easier for people to want to help.... Looks like you may have figured out your problem.... No changes to your original code other than cosmetic <?php $staffQuery = mysqli_query($staffConnected, "SELECT `name`, `email`, `department`, `position` FROM `staff` WHERE `class`=2 ORDER BY `department`, `name` ASC") if($staffQuery){ $rowNum=1; $cellNum=0; $amountOfStaffReturned=mysqli_num_rows($staffQuery); if($amountOfStaffReturned>0){ $departmentHeader=false; $content.='<div class="emailHeader">Staff Contacts</div>'; while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)) { $staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position']; $rowName=rowName($rowNum); if($rowNum>1){ $rowEmailClassAdd=' emailRow'; } else { $rowEmailClassAdd=''; } if($cellNum%2==0){ if($departmentHeader!=$staffDepartment) { $content.='<div class="departmentHeader">'.$staffDepartment.'</div>'; $departmentHeader=$staffDepartment; } if($cellNum != 0){ $content.='</div>'; } $content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">'; $rowNum++; } $content .='<div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; if($amountOfStaffReturned%2 != 0 && $cellNum+1 == $amountOfStaffReturned) { $content.='<div class="emailCell"> </div> </div>'; } $cellNum++; } //end while } } Quote Link to comment Share on other sites More sharing options...
HDRebel88 Posted July 22, 2013 Author Share Posted July 22, 2013 (edited) Looks like you may have figured out your problem.... Nope... just ditched using PHP and MySQL and coded it straight in HTML: $content.='<div id="contactusWrapper"> <div class="header">Contact Us</div> <a name="submissionspolicy"></a> <div class="overflowclear" id="contactusGeneralContainer"> <div class="emailHeader">General Contact</div> <div class="overflowclear center" id="emailGeneralFirstRow"> <div class="emailCell"> <div><span class="bold">Company E-Mail</span><br /><a class="contactemail" href="mailto:'.$email.'">'.$emailEscaped.'</a></div> </div> <div class="emailCell"> <div><span class="bold">US Phone</span> <br />'.$phone.'</div> </div> </div> </div> <div class="overflowclear" id="submissionsPolicy"> <div class="emailHeader">Submissions Policy</div> <div id="submissionsText">Currently we do not accept unsolicited submissions.<br/><span class="fourteen">If you choose to send us any material, it will NOT be read and will be immediately destroyed (if in physical form) or deleted (if sent via email). <br /> No material will be returned to you.</span><br /> <div class="submissionNote">Please note, if you choose to disregard this policy and submit materials regardless, you acknowledge that you have read the submission policy and understand that by making such a submission, you understand that KAM Entertainment has no obligation to you or your submission and that you have no claim whatsoever based on such submission.</div></div> </div> <div class="overflowclear" id="contactusExecContainer"> <div class="emailHeader">Executive Contacts</div> <div class="overflowclear" id="emailExecFirstRow"> <div class="emailCell"> <div class="emailTitle">Andrew McCarrick</div> <div class="emailSubTitle">C.E.O./President/Founder</div> <div><a class="contactemail" href="mailto:AMcCarrick@kamentertainment.net">AMcCarrick@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Madison Acres</div> <div class="emailSubTitle">C.O.O./V.P. of Development/Co-Founder</div> <div><a class="contactemail" href="mailto:MAcres@kamentertainment.net">MAcres@kamentertainment.net</a></div> </div> </div> <div class="emailRow overflowclear" id="emailExecSecondRow"> <div class="emailCell"> <div class="emailTitle">Kaylie James</div> <div class="emailSubTitle">C.M.O./V.P. of Marketing/Co-Founder</div> <div><a class="contactemail" href="mailto:KJames@kamentertainment.net">KJames@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Haylie James</div> <div class="emailSubTitle">C.F.O./C.S.O./V.P. of Distribution</div> <div><a class="contactemail" href="mailto:HJames@kamentertainment.net">HJames@kamentertainment.net</a></div> </div> </div> </div> <div class="overflowclear" id="contactusStaffContainer"><div class="emailHeader">Staff Contacts</div> <div class="departmentHeader">Assistants</div> <div class="overflowclear" id="emailStaffOneRow"> <div class="emailCell"> <div class="emailTitle">Diane Bosch</div> <div class="emailSubTitle">Assistant to Haylie and Kaylie James</div> <div><a class="contactemail" href="mailto:DBosch@kamentertainment.net">DBosch@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Lily Scorfield</div> <div class="emailSubTitle">Assistant to Andrew McCarrick</div> <div><a class="contactemail" href="mailto:LScorfield@kamentertainment.net">LScorfield@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffTwoRow"> <div class="emailCell"> <div class="emailTitle">Roka Kino</div> <div class="emailSubTitle">Assistant to Madison Acres</div> <div><a class="contactemail" href="mailto:RKino@kamentertainment.net">RKino@kamentertainment.net</a></div> </div> <div class="emailCell"> </div> </div> <div class="departmentHeader">Information Technology</div> <div class="overflowclear emailRow" id="emailStaffThreeRow"> <div class="emailCell"> <div class="emailTitle">Eiki Akimoto</div> <div class="emailSubTitle">EVP of Information Technology</div> <div><a class="contactemail" href="mailto:EAkimoto@kamentertainment.net">EAkimoto@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Dennis O\'neal</div> <div class="emailSubTitle">Web Design</div> <div><a class="contactemail" href="mailto:DOneal@kamentertainment.net">DOneal@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffFourRow"> <div class="emailCell"> <div class="emailTitle">Martin Evanson</div> <div class="emailSubTitle">Web Development</div> <div><a class="contactemail" href="mailto:MEvanson@kamentertainment.net">MEvanson@kamentertainment.net</a></div> </div> <div class="emailCell"> </div> </div> <div class="departmentHeader">Marketing</div> <div class="overflowclear emailRow" id="emailStaffFiveRow"> <div class="emailCell"> <div class="emailTitle">Kristal York</div> <div class="emailSubTitle">EVP of Marketing</div> <div><a class="contactemail" href="mailto:KYork@kamentertainment.net">KYork@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Aron Patterson</div> <div class="emailSubTitle">Marketing Manager & SVP of PR</div> <div><a class="contactemail" href="mailto:APatterson@kamentertainment.net">APatterson@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffSixRow"> <div class="emailCell"> <div class="emailTitle">Isabella Morris</div> <div class="emailSubTitle">Digital Marketing & SVP of Web Design</div> <div><a class="contactemail" href="mailto:IMorris@kamentertainment.net">IMorris@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Sienna Bibi</div> <div class="emailSubTitle">Graphics Design</div> <div><a class="contactemail" href="mailto:SBibi@kamentertainment.net">SBibi@kamentertainment.net</a></div> </div> </div> <div class="departmentHeader">Operations</div> <div class="overflowclear emailRow" id="emailStaffSevenRow"> <div class="emailCell"> <div class="emailTitle">Maddison Beringer</div> <div class="emailSubTitle">EVP of Business Development</div> <div><a class="contactemail" href="mailto:MBeringer@kamentertainment.net">MBeringer@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Rafael Kramer</div> <div class="emailSubTitle">EVP Business & Legal Affairs</div> <div><a class="contactemail" href="mailto:RKramer@kamentertainment.net">RKramer@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffEightRow"> <div class="emailCell"> <div class="emailTitle">Stephanie Badham</div> <div class="emailSubTitle">Business Development</div> <div><a class="contactemail" href="mailto:SBadham@kamentertainment.net">SBadham@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Katheryne Mayer</div> <div class="emailSubTitle">Business & Legal Affairs</div> <div><a class="contactemail" href="mailto:KMayer@kamentertainment.net">KMayer@kamentertainment.net</a></div> </div> </div> <div class="departmentHeader">Post-Production</div> <div class="overflowclear emailRow" id="emailStaffNineRow"> <div class="emailCell"> <div class="emailTitle">Lilian Tyrell</div> <div class="emailSubTitle">EVP of Post-Production</div> <div><a class="contactemail" href="mailto:LTyrell@kamentertainment.net">LTyrell@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Jerome Black</div> <div class="emailSubTitle">Editor</div> <div><a class="contactemail" href="mailto:JBlack@kamentertainment.net">JBlack@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffTenRow"> <div class="emailCell"> <div class="emailTitle">Lisa Davidson</div> <div class="emailSubTitle">Post-Production Graphics</div> <div><a class="contactemail" href="mailto:LDavidson@kamentertainment.net">LDavidson@kamentertainment.net</a></div> </div> <div class="emailCell"> </div> </div> <div class="departmentHeader">Production</div> <div class="overflowclear emailRow" id="emailStaffElevenRow"> <div class="emailCell"> <div class="emailTitle">Aleesha Rodriguez</div> <div class="emailSubTitle">EVP of Project Development</div> <div><a class="contactemail" href="mailto:ARodriguez@kamentertainment.net">ARodriguez@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Kyle Day</div> <div class="emailSubTitle">Manager of Project Development</div> <div><a class="contactemail" href="mailto:KDay@kamentertainment.net">KDay@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffTweleveRow"> <div class="emailCell"> <div class="emailTitle">Cynthia Griffiths</div> <div class="emailSubTitle">Producer</div> <div><a class="contactemail" href="mailto:CGriffiths@kamentertainment.net">CGriffiths@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Justin Sydney</div> <div class="emailSubTitle">Producer</div> <div><a class="contactemail" href="mailto:JSydney@kamentertainment.net">JSydney@kamentertainment.net</a></div> </div> </div> <div class="departmentHeader">Sales</div> <div class="overflowclear emailRow" id="emailStaffThirteenRow"> <div class="emailCell"> <div class="emailTitle">Christa Archer</div> <div class="emailSubTitle">EVP Sales</div> <div><a class="contactemail" href="mailto:CArcher@kamentertainment.net">CArcher@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Li Feng</div> <div class="emailSubTitle">Sales Director</div> <div><a class="contactemail" href="mailto:LFeng@kamentertainment.net">LFeng@kamentertainment.net</a></div> </div> </div> <div class="overflowclear emailRow" id="emailStaffFourteenRow"> <div class="emailCell"> <div class="emailTitle">Jennifer Hooper</div> <div class="emailSubTitle">Sales Associate</div> <div><a class="contactemail" href="mailto:JHooper@kamentertainment.net">JHooper@kamentertainment.net</a></div> </div> <div class="emailCell"> </div> </div> </div> </div> </div>'; I of course would prefer a PHP/MySQL solution, but not if it's going to be this unreasonably difficult to implement, I'm not going to bother. This is where I got with the PHP code: if($staffQuery=mysqli_query($staffConnected, "SELECT `name`, `email`, `department`, `position` FROM `staff` WHERE `class`=2 ORDER BY `department`, `name` ASC")){ $rowNum=1; $cellNum=0; $checkBlank=0; $amountOfStaffReturned=mysqli_num_rows($staffQuery); if($amountOfStaffReturned>0){ $departmentHeader=false; $content.='<div class="emailHeader">Staff Contacts</div>'; while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)){ $staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position']; $rowName=rowName($rowNum); if($rowNum>1){$rowEmailClassAdd=' emailRow';}else{$rowEmailClassAdd='';} if($cellNum%2==0){ if($cellNum!=0){$content.='</div>';} if($departmentHeader!=$staffDepartment){$content.='<div class="departmentHeader">'.$staffDepartment.'</div>';$departmentHeader=$staffDepartment;} $content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">'; $rowNum++; } if($departmentHeader==$staffDepartment){ $checkBlank++; $content.=' <div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; } elseif($departmentHeader!=$staffDepartment){ if($checkBlank%2==0){ $content.='<div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; } else{ $content.='<div class="emailCell"> </div>'; } $checkBlank=0; } $cellNum++; } $content.='</div>'; } } That gets me here: http://www.kamentertainment.net/staff Close but still not right. The cell that needs to be moved is removed and replaced with the blank cell... however, the removed cell isn't placed in to it's proper department... it just disappears. I'm probably missing something here but not sure what... Edited July 22, 2013 by HDRebel88 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 22, 2013 Share Posted July 22, 2013 here is the basic LOGIC you need to detect when to close the previous section, start a new section, and output data under a section - $departmentHeader=false; while( ... ){ $staffDepartment=$staff['department']; // detect a change in the department header if($departmentHeader!=$staffDepartment){ // the department changed (or is the first one) if($departmentHeader != false){ // not the first section, close out the previous section here... } $departmentHeader=$staffDepartment; // save the header // start a new section here... } // output the data under each section here... } // close out the final section here... Quote Link to comment Share on other sites More sharing options...
HDRebel88 Posted July 22, 2013 Author Share Posted July 22, 2013 (edited) Okay did that, and it's still not quite right (although it is very very close; visually it's right, HTML code-wise its not): (Sorry about the indentations, the forum software is screwing it up) $rowNum=1; $cellNum=0; $amountOfStaffReturned=mysqli_num_rows($staffQuery); if($amountOfStaffReturned>0){ $departmentHeader=false; $content.='<div class="emailHeader">Staff Contacts</div>'; while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)){ $staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position']; $rowName=rowName($rowNum); if($rowNum>1){$rowEmailClassAdd=' emailRow';}else{$rowEmailClassAdd='';} if($departmentHeader!=$staffDepartment){ if($departmentHeader!=false){ $content.='</div>'; } $departmentHeader=$staffDepartment; $content.='<div class="departmentHeader">'.$staffDepartment.'</div>'; $content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">'; $rowNum++; } $content.=' <div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; $cellNum++; } $content.='</div>'; } This results in this HTML code: <div class="emailHeader">Staff Contacts</div> <div class="departmentHeader">Assistants</div> <div class="overflowclear" id="emailStaffOneRow"> <div class="emailCell"> <div class="emailTitle">Diane Bosch</div> <div class="emailSubTitle">Assistant to Haylie and Kaylie James</div> <div><a class="contactemail" href="mailto:DBosch@kamentertainment.net">DBosch@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Lily Scorfield</div> <div class="emailSubTitle">Assistant to Andrew McCarrick</div> <div><a class="contactemail" href="mailto:LScorfield@kamentertainment.net">LScorfield@kamentertainment.net</a></div> </div> ---Missing closing DIV for first row--- ---Missing opening div for second row--- <div class="emailCell"> <div class="emailTitle">Roka Kino</div> <div class="emailSubTitle">Assistant to Madison Acres</div> <div><a class="contactemail" href="mailto:RKino@kamentertainment.net">RKino@kamentertainment.net</a></div> </div> ---Missing empty cell code of <div class="emailCell"> </div>--- </div> <div class="departmentHeader">Information Technology</div> <div class="overflowclear emailRow" id="emailStaffTwoRow"><--- Should be called emailStaffThreeRow <div class="emailCell"> <div class="emailTitle">Dennis O'neal</div> <div class="emailSubTitle">Web Design</div> <div><a class="contactemail" href="mailto:DOneal@kamentertainment.net">DOneal@kamentertainment.net</a></div> </div> <div class="emailCell"> <div class="emailTitle">Eiki Akimoto</div> <div class="emailSubTitle">EVP of Information Technology</div> <div><a class="contactemail" href="mailto:EAkimoto@kamentertainment.net">EAkimoto@kamentertainment.net</a></div> </div> ---Missing closing DIV for third row--- ---Missing opening div for fourth row--- <div class="emailCell"> <div class="emailTitle">Martin Evanson</div> <div class="emailSubTitle">Web Development</div> <div><a class="contactemail" href="mailto:MEvanson@kamentertainment.net">MEvanson@kamentertainment.net</a></div> </div> ---Missing empty cell code of <div class="emailCell"> </div>--- </div> Edited July 22, 2013 by HDRebel88 Quote Link to comment Share on other sites More sharing options...
HDRebel88 Posted July 22, 2013 Author Share Posted July 22, 2013 Alright, I'm 99% sure I just got it... Will test momentarily, then confirm. $rowNum=1; $cellNum=0; $amountOfStaffReturned=mysqli_num_rows($staffQuery); if($amountOfStaffReturned>0){ $departmentHeader=false; $content.='<div class="emailHeader">Staff Contacts</div>'; while($staff=mysqli_fetch_array($staffQuery, MYSQLI_ASSOC)){ $staffName=$staff['name']; $staffEmail=$staff['email']; $staffDepartment=$staff['department']; $staffPosition=$staff['position']; $rowName=rowName($rowNum); if($rowNum>1){$rowEmailClassAdd=' emailRow';}else{$rowEmailClassAdd='';} if($departmentHeader!=$staffDepartment){ if($cellNum%2!=0){ $content.='<div class="emailCell"> </div>'; $cellNum++; } if($departmentHeader!=false){ $content.='</div>'; } $departmentHeader=$staffDepartment; $content.='<div class="departmentHeader">'.$staffDepartment.'</div>'; } else{if($cellNum%2==0){$content.='</div>';}} if($cellNum%2==0){ $content.='<div class="overflowclear'.$rowEmailClassAdd.'" id="emailStaff'.ucfirst($rowName).'Row">'; $rowNum++; } $content.=' <div class="emailCell"> <div class="emailTitle">'.$staffName.'</div> <div class="emailSubTitle">'.$staffPosition.'</div> <div><a class="contactemail" href="mailto:'.$staffEmail.'">'.escapeemail($staffEmail).'</a></div> </div>'; $cellNum++; } $content.='</div>'; } Thanks for the help guys, certainly lead me to the right path. Quote Link to comment Share on other sites More sharing options...
Solution HDRebel88 Posted July 22, 2013 Author Solution Share Posted July 22, 2013 (edited) It does indeed seem like this is working now... Thanks again guys. Edited July 22, 2013 by HDRebel88 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.