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
<!--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']): ?> <?php echo $record['first_name'] ?><?php endif ?><?php if ($record['last_name']): ?> <?php echo $record['last_name'] ?><?php endif ?>
<?php if ($record['company']): ?><br/> <?php echo $record['company'] ?><?php endif ?>
<?php if ($record['city']): ?><br/> <?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"> <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 >></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"><< prev</a>
<?php else: ?>
<< 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 >></a>
<?php else: ?>
next >>
<?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
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!
Chris
Re: [chris] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page
By Codee - August 30, 2010
Re: [equinox69] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page
By Codee - September 8, 2010
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
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
looks like that took care of it. Thanks!
why the diff?
Re: [equinox69] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page
By Chris - September 9, 2010
Oh, wow. I must have posted without coffee that day! I gave you the wrong code. The code I meant to give you was:
<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>
I've updated my post above to be correct too.
Jason's method works just as well, so you can use whichever you wish. :)
Chris
Re: [chris] Creating Sequential-Itemed Table List Page instead of Line Itemed List Page
By Codee - September 9, 2010