Displaying list entry with empty thumbnail & organizing info

7 posts by 2 authors in: Forums > CMS Builder
Last Post: November 16, 2016   (RSS)

By tbernatonis - November 15, 2016

I am attempting to restructure the employee directory for my organization from scratch. I have 2 issues:

1. When the employees are displayed, the ones without an uploaded headshot show up as just a blank space (without info). Just 2 break lines. We have several temp employees that don't have headshots and would like to display just their contact info.

2. How would I put the php into a table to organize the information better? What I'm trying to do is have the headshot on the right, Name, title and department middle, and contact info on the left.

Here's the code I have so far:

<?php foreach ($directoryRecords as $record): ?>
<?php foreach ($record['photo'] as $index => $upload): ?>
<img class="float-left" style="margin: 0px 20px;" src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<strong>
<?php echo htmlencode($record['first_name']) ?>&nbsp;
<?php echo htmlencode($record['last_name']) ?></strong><br/>
<?php echo htmlencode($record['title']) ?><br/>
<?php echo htmlencode($record['department_01']) ?><br/>
<?php echo htmlencode($record['department_02']) ?><br/>
Office: <?php echo htmlencode($record['office_number']) ?><br/>
Phone: <?php echo htmlencode($record['phone']) ?><br/>
Email: <?php echo '<a href="mailto:'.htmlencode($record['email']).'">'.htmlencode($record['email']).'</a>'; ?>
<?php endforeach ?>
<hr />
<?php endforeach ?>
<?php if (!$directoryRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

By Damon - November 15, 2016

Hi,

Try this code for displaying employees in a table:

<table>
<tr>
<td><strong>Image</strong></td>
<td><strong>Name</strong></td>
<td><strong>Title</strong></td>
<td><strong>Deparments</strong></td>
<td><strong>Office</strong></td>
<td><strong>Phone</strong></td>
<td><strong>Email</strong></td>
</tr>
<?php foreach ($directoryRecords as $record): ?>
<tr>
<td>
<?php foreach ($record['photo'] as $index => $upload): ?>
<img class="float-left" style="margin: 0px 20px;" src="<?php echo htmlencode($upload['thumbUrlPath']) ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" />
<?php break; //only show one image ?>
<?php endforeach ?>

<?php if() : // if there is no image uploaded, show this image ?>
<img src="/image.jpg" />
<?php endif; ?>
</td>
<td>
<strong>
<?php echo htmlencode($record['first_name']) ?>&nbsp;
<?php echo htmlencode($record['last_name']) ?>
</strong>
</td>
<td>
<?php echo htmlencode($record['title']) ?>
</td>
<td>
<?php echo htmlencode($record['department_01']) ?>
<?php if($record['department_02']) : ?>
<br/><?php echo htmlencode($record['department_02']) ?>
<?php endif; ?>
</td>
<td>
<?php echo htmlencode($record['office_number']) ?>
</td>
<td>
<?php echo htmlencode($record['phone']) ?>
</td>
<td>
<?php echo '<a href="mailto:'.htmlencode($record['email']).'">'.htmlencode($record['email']).'</a>'; ?>
</td>
<?php endforeach ?>
</table>

<?php if (!$directoryRecords): ?>
No records were found!<br/><br/>
<?php endif ?>

I added an if statement to show a image.jpg if the employee doesn't have an uploaded image. This can be changed to display another image or any other content (ex. No image available) .

Let me know if you have any other questions.

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By tbernatonis - November 16, 2016

Hi Damon,

I tried using the code you provided but get an error:

Parse error: syntax error, unexpected ')' in C:\inetpub\wwwroot\directories\directory.php on line 62

That line would be:

<?php if() : // if there is no image uploaded, show this image ?>

Let me know if you need any more info.

Thank you!

Tony

By tbernatonis - November 16, 2016

Hi,

I pretty much have it where I want it. You are AMAZING! 

All I need now is to add an <hr/> between entries. Is this possible with a table? If so, how? I've attached my php file.

Tony

Attachments:

directory2.php 4K

By Damon - November 16, 2016

Hi Tony,

All I need now is to add an <hr/> between entries. Is this possible with a table? If so, how? I've attached my php file.

Just before this code, <?php endforeach ?>, on line 59 add this code to display a horizontal rule under all three columns and between each employee entry:

<tr>
 <td colspan="3">
  <hr />
 </td>
</tr>
<?php endforeach ?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

By tbernatonis - November 16, 2016

Thanks Damon,

you're a life saver!

-Tony