Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

8 posts by 3 authors in: Forums > CMS Builder
Last Post: September 9, 2010   (RSS)

By Codee - August 27, 2010

I have a list page viewer that display the semi-typical line-item list page and the page uses the following code:
<!--display record code begins-->
<?php foreach ($testimonialsRecords as $record): ?>
<table width=100% border="0" cellpadding="0" cellspacing="0">
<tr>
<td valign="top">
<?php if ($record['title']): ?><b/>"<?php echo $record['title'] ?>"</b/><br/><br/><?php endif ?>
<?php if ($record['first_name']): ?>&nbsp;&nbsp;&nbsp;<?php echo $record['first_name'] ?><?php endif ?><?php if ($record['last_name']): ?>&nbsp;<?php echo $record['last_name'] ?><?php endif ?>
<?php if ($record['company']): ?><br/>&nbsp;&nbsp;&nbsp;<?php echo $record['company'] ?><?php endif ?>
<?php if ($record['city']): ?><br/>&nbsp;&nbsp;&nbsp;<?php echo $record['city'] ?><?php endif ?><?php if ($record['state']): ?>, <?php echo $record['state'] ?><br/><br/><?php endif ?>

<a href="<?php echo $record['_link'] ?>" class="prevnext">&nbsp;&nbsp;&nbsp;<font size="2">...click to view more details</font></a>
</td>

<td valign="top" align="right">
<a href="<?php echo $record['_link'] ?>" border="0">
<!-- STEP 2a: Display Uploads for field 'photo' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['photo'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" border="0" align="right" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' />
<?php break; ?>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" border="0" align="right" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt='' />

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->
</a>
</td>
</tr>
</table>
<?php endforeach; ?>

<?php if ($testimonialsMetaData['invalidPageNum']): ?>
Results page '<?php echo $testimonialsMetaData['page']?>' not found, <a href="<?php echo $testimonialsMetaData['firstPageLink'] ?>">start over &gt;&gt;</a>.<br/><br/>
<?php elseif (!$testimonialsRecords): ?>
Those records are currently not available. Please click BACK in your browser.<br/><br/>
<?php endif ?>
<!-- /STEP2: Display Records -->


<!-- STEP3: Display Page Links (Paste anywhere below "Load Record List") -->
<?php if ($testimonialsMetaData['prevPage']): ?>
<a href="<?php echo $testimonialsMetaData['prevPageLink'] ?>" class="prevnext">&lt;&lt; prev</a>
<?php else: ?>
&lt;&lt; prev
<?php endif ?>

- page <?php echo $testimonialsMetaData['page'] ?> of <?php echo $testimonialsMetaData['totalPages'] ?> -

<?php if ($testimonialsMetaData['nextPage']): ?>
<a href="<?php echo $testimonialsMetaData['nextPageLink'] ?>" class="prevnext">next &gt;&gt;</a>
<?php else: ?>
next &gt;&gt;
<?php endif ?>
<!--display record code ends-->


What I would like this page to do instead is build a set-sized table of 5 listings per row with a max of 5 rows per page, and if there is more than 25 listings then the prev/next page links show that.

So instead of
row 1: listing 1 text/listing 1 thumbnail
row 2: listing 2 text/listing 2 thumbnail
row 3: listing 3 text/listing 3 thumbnail
row 4: listing 4 text/listing 4 thumbnail
row 5: listing 5 text/listing 5 thumbnail
row 6: listing 6 text/listing 6 thumbnail
row 7: listing 7 text/listing 7 thumbnail
...rows 8-24 and...
row 25: listing 25 text/listing 25 thumbnail

it would display
row 1: listing 1 thumbnail and text/listing 2 thumbnail and text/listing 3 thumbnail and text/listing 4 thumbnail and text/listing 5 thumbnail and text

row 2: listing 6 thumbnail and text/listing 7 thumbnail and text/listing 8 thumbnail and text/listing 9 thumbnail and text/listing 10 thumbnail and text

row 3: etc...

How can I accomplish this simply and readily?

Re: [equinox69] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Chris - August 30, 2010 - edited: September 9, 2010

Hi equinox69,

You can do this by adding a few lines of code. First, you'll want to initialize a $count variable to 0 before your foreach. Then, when displaying a record, start a new table row (e.g. </tr><tr>) when the $count is a multiple of 5 and then increment the $count.

Here's an example:

<table>
<tr>
<?php $count = 0; ?>
<?php foreach($testimonialsRecords as $record): ?>
<?php if ($count++ % 5 == 0): ?>
</tr><tr>
<?php endif ?>


<!-- insert record display code here -->

<?php endforeach ?>
</tr>
</table>


Does this help? Please let me know if you have any questions.

EDIT: fixed IF test!
All the best,
Chris

Re: [chris] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Codee - August 30, 2010

Thanks Chris! I'll try it out and let you know!

Re: [equinox69] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Codee - September 8, 2010

Chris,
It's "almost" working. At the end of the second row is the 10th unit, 5 per row, and number 11 is posting on the end of the second row instead of creating a new row for units 11-15.

Please help. Here's a snippet of code:
<table width=100% border="0" cellspacing="4" cellpadding="0">
<tr>
<?php $count = 0; ?>
<?php foreach($entertainersRecords as $record): ?>
<?php if ($count++ == 5): ?>
</tr><tr>
<?php endif ?>

<td valign="top">
<center>
<a href="<?php echo $record['_link'] ?>" class="prevnext" border="0">
<!-- STEP 2a: Display Uploads for field 'image' (Paste this anywhere inside STEP2 to display uploads) -->
<!-- Upload Fields: num, createdTime, tableName, fieldName, recordNum, preSaveTempId, filePath, filename, extension, thumbFilePath, isImage, hasThumbnail, urlPath, width, height, thumbUrlPath, thumbWidth, thumbHeight, info1, info2, info3, info4, info5 -->
<?php foreach ($record['image'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" border="0" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt="" /><br/>
<?php break; ?>
<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" border="0" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt="" /><br/>

<?php else: ?>
<a href="<?php echo $upload['urlPath'] ?>">Download <?php echo $upload['filename'] ?></a><br/>

<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->
<?php if ($record['title']): ?>
<b/>'<?php echo $record['title'] ?>'</b/><br/>
<?php endif ?>
<?php echo $record['first_name'] ?> <?php echo $record['last_name'] ?><br/><br/>

</center>
</a>
</td>

<?php endforeach ?>
</tr>
</table>

Re: [equinox69] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Jason - September 9, 2010

Hi,

Try changing your code to this:

<?php $count = -1; ?>
<?php foreach($entertainersRecords as $record): ?>
<?php if (++$count == 5): ?>
<?php $count=0;?>
</tr><tr>
<?php endif ?


Give that a try.

Hope this helps.
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Codee - September 9, 2010

Jason,

looks like that took care of it. Thanks!

why the diff?

Re: [chris] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page

By Codee - September 9, 2010

Many thanks to both you and Jason - it's working terrifically and the client's happy!