Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Generating HTML, if elsif 1

Status
Not open for further replies.

SPrelewicz

Programmer
Jul 16, 2001
124
US
Here is what I am trying to do:

I have a text database with a ton of entries. They are journal titles and corresponding hyperlinks and types. What I've been asked to do, when a user clicks on a type, a list of journal titles, with thier links is generated for all of that type. This is done. They want me to add an alphabet thing on top, so when a letter is clicked it jumps down to the first title with that letter. Of course, I know this is done with the HTML name attribute and #. Any suggestions, however as to how I can attach the name attribute to the correct url? This would be done dynamically, through CGI as the page is generated. I thought about using the lcfirst command, but don't know what exactly it does. Thanks.
 
well, here's an example that might help you figure this out (a little sloppy cause i couldn't remember how to get the first letter of a string without removing it. sorry):[tt]
#...
my @list_of_data = &get_data($filename, $arg1, $arg2);
@list_of_data = sort @list_of_data;
my $last_letter = 0;
foreach my $item (@list_of_data)
{
my $this_letter = substr($item, 0, 1);
if ($last_letter != $this_letter)
{
$last_letter = $this_letter;
print &quot;<h3><u>$this_letter</u></h3><br>\n&quot;;
}
print $this_letter . $item;
}[/tt]

the idea is to have a cache to remember what letter you're on, and if the next item doesn't start with the same letter, you print something unique, or whatever. hope this helps. &quot;If you think you're too small to make a difference, try spending a night in a closed tent with a mosquito.&quot;
 
To get the first character of a string:
Code:
$firstchar = substr($string, 0, 1);
Tracy Dryden
tracy@bydisn.com

Meddle not in the affairs of dragons,
For you are crunchy, and good with mustard.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top