Displaying list entry with empty thumbnail & organizing info

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

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 Damon - November 16, 2016

I missed some code. Here is the complete code:

<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(!$record['photo']) : // 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 ?>

If this doesn't work, can you reply with your complete file as an attachment for me to review?

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,

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