9three Posted June 24, 2009 Share Posted June 24, 2009 Hey, I'm running this: while($row = db_fetch_array($results)) { $tempLetter = substr($row['products_description'], 0, 1); echo '<a href="' . link_url(PAGENAME_PRODUCTS_DESCRIP, 'part_number=' . $row['part_number']) . '">'.$tempLetter.'</a>'; } echo '</div>'; What this does is pull the information from my DB and then I grab the first letter from each product description. What I'm trying to do is pull only the first letter AND display it ONCE. For example if the information pulled three letter Bs and 10 letter As, it should only display each letter once. Can someone lend a hand please? Link to comment https://forums.phpfreaks.com/topic/163491-solved-displaying-first-letter-and-only-once/ Share on other sites More sharing options...
Alex Posted June 24, 2009 Share Posted June 24, 2009 $used = Array(); while($row = db_fetch_array($results)) { $tempLetter = substr($row['products_description'], 0, 1); if(!in_array($tempLetter, $used)) { $used[] = $tempLetter; echo '<a href="' . link_url(PAGENAME_PRODUCTS_DESCRIP, 'part_number=' . $row['part_number']) . '">'.$tempLetter.'</a>'; } } echo '</div>'; Link to comment https://forums.phpfreaks.com/topic/163491-solved-displaying-first-letter-and-only-once/#findComment-862627 Share on other sites More sharing options...
9three Posted June 24, 2009 Author Share Posted June 24, 2009 thanks got it Link to comment https://forums.phpfreaks.com/topic/163491-solved-displaying-first-letter-and-only-once/#findComment-862630 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.