Break between alphabetic groups

5 posts by 3 authors in: Forums > CMS Builder
Last Post: March 23, 2009   (RSS)

By rconring - March 19, 2009

Being new to PHP, I am having a bit of a problem forcing a line or double break between sections in an alphabetized list of links to other sites. I don't know the syntax for doing this based on first character change. I did a temporary workaround by using a line_after checkbox on each entry and if true, printing a line:
<?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.
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [ross] Break between alphabetic groups

By rconring - March 19, 2009

Ross ...

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
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987

Re: [rconring] Break between alphabetic groups

By Dave - March 23, 2009

Hi Ron,

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.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Break between alphabetic groups

By rconring - March 23, 2009

Dave ....
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!!
Ron Conring
Conring Automation Services
----------------------------------------
Software for Business and Industry Since 1987