i'm creating a hebrew glossary page for a client using ASP and MySQL. i want to create a recordset and then loop through the results, grouping by the first letter and each with its own heading... something like this :
A
Apple Avacado Ape Bilge beetleetcetc
can anyone suggest a good way of doing this? i did find a jquery plugin which would be perfect (and automatic) : http://www.ihwy.com/Labs/Demos/Current/jquery-listnav-plugin.aspx the only problem i had is that it doesn't work at all for hebrew characters.
so, any suggestions?
You don't need to group your data, just loop through it this way. Adjust to suit your database fields accordingly:
<%
set conn = server.createobject("ADODB.Connection")
Set RS = Server.CreateObject("ADODB.Recordset")
RS.Open "Select * FROM myTable order by Term asc",conn,3,3
lastLetter = ""
do while not RS.eof
firstLetter = left(RS("Term"),1)
if lastLetter <> firstLetter then
response.write("<b>" & firstLetter & "</b><br />"
end if
resonse.write(RS("Term")&"<br />"
lastLetter = firstLetter
RS.movenext
loop
%>
I had to do something similar. I don't know ASP but in PHP I used a simple array like so
$r = mysql_query( ' select * from table ' );
$array = array();
while( $row = mysql_fetch_assoc( $r ) ) {
$array[strtolower(substr($row['name'],0,1))][] = $row;
}
This creates an array with nested arrays. The key of the highest array is the first letter of the name column. Then each one of those has a nested array with the row.
You can no doubt do the same in ASP.
精彩评论