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? Quote 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>'; Quote 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 Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.