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 Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ABC listing of surnames in a recordset 1

Status
Not open for further replies.

mlawson

Technical User
Joined
Jun 12, 2001
Messages
197
Location
GB
Hi Folks,

A couple of you guys asked me a copy of the script which would allow an alphabetical listing of surnames (it couls be anything) from a recordset. Well I have pasted it in below for your enjoyment. Note that it is basically some modified ASP but if you are familiar with the code generated by UD during recordset set up and can navigate through it, it is quite a cool little script.

<%
for counter = 65 to 90
' for next routine to create hyperlinks alphabetically targeted
' to the current page
%>
<a href=&quot;<%= request.servervariables(&quot;script_name&quot;)%>?u_letter=&#<%= counter %>;&quot;>
&#<%= counter %>;</a>
<% next %>
</p>
<p>&nbsp;</p>
<p>

<%
u_letter=trim(request.querystring(&quot;u_letter&quot;))
'if the user clicked a link then search the db
if u_letter<>&quot;&quot; then
accessdb=&quot;lifescience&quot;
cn=&quot;DRIVER={Microsoft Access Driver (*.mdb)};DBQ=&quot; & Server.MapPath(&quot;database.mdb&quot;) & &quot;;&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)

sql = &quot;select * from tblStaff where left(stfSurname,1)='&quot;& u_letter &&quot;' order by stfSurname asc&quot;

rs.Open sql, cn
'if the search ends in no results display a
'no results found mesage
if rs.eof then
%>
No Staff begin with the letter <%= u_letter %>
<% else
do while not rs.eof
'display all observations found
%>
<br>
<%= rs(&quot;stfSurname&quot;) %>
<%
rs.movenext
loop
end if ' end check for obs
end if ' end check for user input
%>

This is not one of my scripts, I happened across it in a FAQ section of and ASP site, if I can remember who initiated it I'll credit them at a later date

Have fun.

M
(Mod. Sorry for the length! ;))
 
Hi Mlawson,

That script is really good!

Can you assist me in modifying it a bit more.

I would like to add an additional field to it - compID as well as companyName.

also

Where it lists out by alphabetical. I want to then have the compID set to ahref anchor tag - pops up a separate window with the detail.

You can see a working method with the code you have up top, and the code I had existing before on the bottom


Log in as test and test

Thank you in advance for any assistance
 
schase,

Had a look at what you want, it seems the way forward is to fiddle with the UD coding for a detail page.
1. Create a 'go to detail page link' and same old, same old, pass URL etc
2. Then create a Open Browser window behaviour and pop in your link page as 1 (ie detail.asp)
3. Now firstly change the MouseOver to MouseDown for the behaviour in no2 (now roll your scripting sleeves up!)
4. Open your coding and do the following;
-highlight and cut the code directly after the a href tag, replace it with a #
- go to the popup javascript along the same line and delete the detail.asp code and paste in your MM code.
-F12 it and try it out.
(I hasten to add this is all from memory I have got the code screwed up, I'll try it out at any rate). If you want a working example, try my draft server at:
and once you open the staff list click on the name of the member.

Hope this helps.

Have fun.

M
 
Thats perfect for what I want,

Lemme tackle into it.

Thanks M, i'll post the results.
 
I think I must be very very close

But it wont pass the # along to pull up that anchor tag.

<A HREF=&quot;#&quot; onMouseDown=&quot;MM_openBrWindow('company.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & &quot;CompID=&quot; & Recordset1.Fields.Item(&quot;CompID&quot;).Value %>','Company','scrollbars=yes,width=800,height=300')&quot;><%= rs(&quot;CompID&quot;) %></A>

It does pop up, but then defaults to the top, not the anchor.

Any idea?

 
It going to be difficult to try to point the 'detail' page to a long static page interspersed with &quot;#&quot; anchors, primarily because your #s aren't ID specific (based on your link, which came up with a javascript error this time, have you been fiddling?) or lifted from a data source.
You're gonna love this...the only way to get the company to appear on the detail page is to have the DP populated from a dataset for each of your companies, unless you want to fiddle with putting each of your anchors into a db and pull them from there (check out the Tcubed tutorial for dynamic FAQs, good tute).

Sorry the news isn't probably what you wanted to hear, but that's how I'd do it (ala the link I offered above)

Have (lots of) fun.

M
 
Hey, yeah i've been fiddling.

Actually it does lift from a data source. And the anchors are Unique value specific I just have the one table repeat region - and the anchors set accordingly - of course I could always change the Anchor from field CompID to the standard autonumber ID if it works better.

If I understand right - the way you have it is the method I'm trying to accomplish. I think it's something small to get it to take off.
 
Alright I getcha,

your code is;

<A HREF=&quot;#&quot; onMouseDown=&quot;MM_openBrWindow('company.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & &quot;CompID=&quot; & Recordset1.Fields.Item(&quot;CompID&quot;).Value %>','Company','scrollbars=yes,width=800,height=300')&quot;><%= rs(&quot;CompID&quot;) %></A>

for the javascript to function and find the # you have to place it within the bounds of the function Ie the () so move the last bit before the </a> tag back into the URL string and try this;

<A HREF=&quot;#&quot; onMouseDown=&quot;MM_openBrWindow('company.asp?<%= MM_keepURL & MM_joinChar(MM_keepURL) & &quot;CompID=&quot; & Recordset1.Fields.Item(&quot;CompID&quot;).Value %>#<%= rs(&quot;CompID&quot;) %>','Company','scrollbars=yes,width=800,height=300')&quot;></A>

I think that's right, you see where I've gone with the # story?

Hope that does something correct!

Have fun.

M
 
yea I see that and you moved the <% rs(&quot;compId) %> over
lol

now there is nothing showing.
 
Have you tried changing the cursor type from forward only to dynamic (given that you are passing the ID more than once into the detail page)

Drop me a note next time, I think we're clogging up the forum a bit.

M

design@1stclass.uk.com
 
Not clogging it up guys.. developing an issue.

We only learn by asking, sometimes it is handy to read other peoples problems just for future knowledge
Live long and make your kids suffer..
 
Point taken Cheech,

We'll try and get a solution and then load the fix up for the forum, you do have a policy on naughty words after all

;)

Have fun

M
 
lol we got it, I said plenty of Naughty words.

Twas my own stupidity. :)

 
(Take 2-last post disappeared into the ether somewhere)

To summarise the interesting dialog that took place between myself and schase, the script I posted back at the very top has 2 issues within it. The function 'counter' generates an integer that is assigned to a maximum of 25 hits reported back based on somebody clicking one of the alphabetical chraracters. This then hyperlinks the field that has been searched on (ie surname in may case of a staff search) based on the integer allocated to it (this is a redundant function that does nothing other than make each hit unique within the collection.
2. What I did then was to apply a staff detail page for each member by creating a second recordset (identical in name for the 'rs' set named in the 'ABC' script and dragged the data fields to an appropriate, repeated region in a nice clean table. So, what? Well, the detail page was a popup window which used both the 'go to detail' page server behaviour and the 'open browser window' (behaviour). The coding employed in that is in an other post up there somewhere. Just be sure to pass the ID into the detail page to ensure the contents are filtered according to ID and you're off! :)

This character building exercise (as schase will confirm) is a good little exercise in the use of raw ASP in conjunction with UD, something that may scare the pants of pure UD programmers, but believe me, will make you look at ASP in a different light!

Have fun

M
 
I agree with M

I had to learn to hand code ASP first, then got a copy of UD. BUt now I have a fairly good idea over what UD is doing with the code I can rip it apart and make it do what I want :-) Live long and make your kids suffer..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top