Jump to content

Recommended Posts

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?

$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>';

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.