Break between alphabetic groups
5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 23, 2009 (RSS)
By rconring - March 19, 2009
<?php foreach ($listRows as $record): ?>
<a target="_blank" title="<?php echo $record['screen_tip'] ?>" href="<?php echo $record['web_address'] ?>"><?php echo $record['title'] ?></a><br />
<?php if ($record['line_after'] == '1'): ?>
<hr width="50%" size="1" style="color: #CC3300">
<?php endif ?>
<?php endforeach ?>
I have done this in other languages ... just PHP challenged. It has to be simple.
Your help would be appreciated.
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
Re: [rconring] Break between alphabetic groups
By ross - March 19, 2009
Thanks for posting!
How are you entering the links into your system? Is it one article for each link?
Could you send me a link of the page you are working on?
Thanks!
Cheers,
Ross Fairbairn - Consulting
consulting@interactivetools.com
Hire me! Save time by getting our experts to help with your project.
Template changes, advanced features, full integration, whatever you
need. Whether you need one hour or fifty, get it done fast with
Priority Consulting: http://www.interactivetools.com/consulting/
Re: [ross] Break between alphabetic groups
By rconring - March 19, 2009
Thanks for your response. This is a "Links to Others" page ... simply a page dedicated to Gratefule Dog Bakery's patrons and business friends. All I am trying to accomplish is to separate the alphabetic title groups with a space or line for readability. I need the php logic to detect the first character change in the title. and print a line. I am currently forcing a line if the records "line_after" field is checked. The record consists of 4 fields, link text (title), web URL, rollover text, and line_after checkbox.
Here is the display code:
<?php foreach ($linksRecords as $record): ?>
<a target="_blank" title="<?php echo $record['screen_tip'] ?>" href="<?php echo $record['web_address'] ?>"><?php echo $record['title'] ?></a>
<br />
<?php if ($record['line_after'] == '1'): ?>
<hr width="50%" size="1">
<?php endif ?>
<?php endforeach ?>
Resulting this page: http://gratefuldogbakery.com/links.php
Thanks, Ross
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987
Re: [rconring] Break between alphabetic groups
By Dave - March 23, 2009
Try this (new code in red):
<?php foreach ($linksRecords as $record): ?>
<a target="_blank" title="<?php echo $record['screen_tip'] ?>"
href="<?php echo $record['web_address'] ?>"><?php echo $record['title'] ?></a><br />
<?php
$letter = substr($record['title'], 0,1);
if ($letter != @$lastLetter) { print '<hr width="50%" size="1">'; }
$lastLetter = $letter;
?>
<?php endforeach ?>
Let me know if that works for you.
interactivetools.com
Re: [Dave] Break between alphabetic groups
By rconring - March 23, 2009
Thanks so much for your reply. The code worked like a champ. I added it to my collection of " Snippets for the PHP challenged". I ended up placing the code BEFORE the link and printing a break rather than a line. Looks better and works fine.
Thanks again for perfectly awsome support!!
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987