Hopefully very simple display question

13 posts by 5 authors in: Forums > CMS Builder
Last Post: January 30, 2010   (RSS)

Hi all,

I have a client who is looking to have cms builder provide a listing of used caravans on his web pages with search, he has seen this site http://www.bridlingtoncaravans.com/used-static-caravans.aspx (just click search button to get listings) and would like his output formatted in a similar way, rows of three vans in nice rounded boxes. Unfortunately i havent got the first clue as to how to go about producing the output in this way rather than a simple linear listing, is this a simple process? has anyone done something similar who could possible post their code so that I could try to fathom out what I need to do.

Any help would be appreciated



Thanks in advance for any help

Re: [willydoit] Hopefully very simple display question

By Chris - November 30, 2009 - edited: January 11, 2010

Hi willydoit,

To lay out your output in columns, you can use a table with some PHP code which starts a new table row after every 3 records are displayed. Here's a simple example:

<table>
<tr>
<?php foreach ($myRecords as $record): ?>
<td>
<?php echo $record['title'] ?> ... add your record display code here
</td>
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?>
</tr><tr>
<?php endif ?>
<?php endforeach ?>
</tr>
</table>


Please note that you'll need to change the code in red to suit your configuration.

I hope this makes sense. Please let me know if you have any questions.

EDIT: fixed position of row-break code
All the best,
Chris

Re: [chris] Hopefully very simple display question

Hi Chris,

Thank you for that, I will give that a try this week and let you know if I need any further help but I am sure I can put something together from your example.

Thanks again your help as always is appreciated

Re: [willydoit] Hopefully very simple display question

By willydoit - January 6, 2010 - edited: January 6, 2010

Hi Chris,

Sorry its taken so long to get back, client and christmas holidays etc, anyway have used your suggestion but just have a small issue,when the table is created I find that the first row doesnt fill all the cells, ie row 1 has three cells but only the first two are occupied, the last cell is empty, subsequesnt rows display fine so I suspect I should be setting an initial value somewhere but unsure what or where, my code used for this section is below.

I am working on things at present but the effect can be seen at http://www.highfield-caravans.co.uk/test/stocklist.php

Thanks in advance for any help.

<table width="90%" border="8" align="center" cellspacing="5" cellpadding="5"> <tr> <?php foreach ($stockRecords as $record): ?> <?php $maxCols=3; if (@++$count % $maxCols == 0): ?> </tr><tr> <?php endif ?> <td>
<strong><?php echo $record['make'] ?> - <?php echo $record['model'] ?></strong><br/>
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt='' /><br/>

<?php else: ?>


<?php endif ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->
Location: <?php echo $record['location'] ?><br/>
Condition: <?php echo $record['condition'] ?><br/>
Price: <?php echo $record['price'] ?><br/>

More Details: <a href="<?php echo $record['_link'] ?>">Click Here..</a><br/>
<hr/>
<?php endforeach; ?>
<?php if (!$stockRecords): ?>
Sorry no records were found!<br/><br/>
<?php endif ?>


</td> </tr> </table>

Re: [chris] Hopefully very simple display question

Hi Chris,

Thanks for the response, I tried your suggestions to no avail, the only section I had that code was at the end of the image insert code and putting the </td> at that location simply resulted in a single column with no images so I have removed it and am back where I started, I have attached the full page of code if it helps, I am sure it is something simple but no-one else seems to have encountered the issue so I am wondering if it could be some anomoly caused by the code being displayed in a nested table or something.

Anyway, code is attached so hope you can help, as mentioned earlier the working page can be seen at http://www.highfield-caravans.co.uk/test/stocklist.php

Thanks in advance

Re: [willydoit] Hopefully very simple display question

By Donna - January 8, 2010

Hi Willy,

Looks like the attachment didn't come through, can you try that again? :)
Donna

--
support@interactivetools.com

Re: [Donna] Hopefully very simple display question

Hi,

I have tried the upload again, sorry about that, seems fine this time.
Attachments:

stocklist.php 9K

Re: [willydoit] Hopefully very simple display question

By Chris - January 11, 2010 - edited: January 11, 2010

Hi willydoit,

Please move the count code to the bottom of the foreach block, just before endforeach:

<table width="90%" border="0" align="center" cellspacing="5" cellpadding="5"> <tr> <?php foreach ($stockRecords as $record): ?><td>
<strong><?php echo $record['make'] ?> - <?php echo $record['model'] ?></strong><br/>
<?php foreach ($record['images'] as $upload): ?>
<?php if ($upload['hasThumbnail']): ?>
<img src="<?php echo $upload['thumbUrlPath'] ?>" width="<?php echo $upload['thumbWidth'] ?>" height="<?php echo $upload['thumbHeight'] ?>" alt='' /><br/>

<?php elseif ($upload['isImage']): ?>
<img src="<?php echo $upload['urlPath'] ?>" width="<?php echo $upload['width'] ?>" height="<?php echo $upload['height'] ?>" alt='' /><br/>
<?php else: ?>
<?php endif ?><?php break; ?>
<?php endforeach ?>
<!-- STEP2a: /Display Uploads -->

Condition: <?php echo $record['condition'] ?><br/>
Price: <?php echo $record['price'] ?><br/>

Currently located at:<br/> <?php echo $record['location'] ?><br/>

For more details please <a href="<?php echo $record['_link'] ?>">Click Here..</a><br/>
<hr/>
</td>
<?php $maxCols=3; if (@++$count % $maxCols == 0): ?></tr><tr><?php endif ?>

<?php endforeach; ?>


I've also added a </td> in there that you were missing.

Sorry about that! I've edited my earlier post to have this in the correct spot. Not sure what I was thinking...

I hope this helps. Please let me know if you have any questions.
All the best,
Chris

Re: [chris] Hopefully very simple display question

Thanks Chris,

That worked a treat.