473,406 Members | 2,208 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

Clickable Aphabetical Listing from MySQL

I've got a list of towns in a MySQL database, which I currently pull from
the database ... e.g. http://www.local-hotel.com/townsall/AU/

I now want to put a [A] [b] [C] etc menu at the top, which will click to the
start of the towns with that letter using index.html#A .... I am guessing
that the best way would be to simply compare the first letter of the current
town to the first letter of the previous town. However, I would also need to
put in non-clickable menu letter (i.e. there are no towns beginning with Z)

How'd you lot plan this simple task?

Thanks

Nick
Jul 16 '05 #1
5 8174
elyob wrote:
I've got a list of towns in a MySQL database, which I currently pull from
the database ... e.g. http://www.local-hotel.com/townsall/AU/

I now want to put a [A] [b] [C] etc menu at the top, which will click to the
start of the towns with that letter using index.html#A .... I am guessing
that the best way would be to simply compare the first letter of the current
town to the first letter of the previous town. However, I would also need to
put in non-clickable menu letter (i.e. there are no towns beginning with Z)

How'd you lot plan this simple task?

Thanks

Nick


Start with
select distinct substring(town, 1, 1) from table order by 1
to get all the first letters for which there are available towns.

Based on that, build the [A] [b] [C] etc menu, with all the letters
but no link to unavailable towns.
Makes sense?

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #2
Message-ID: <7m********************@news-text.cableinet.net> from elyob
contained the following:
I now want to put a [A] [b] [C] etc menu at the top, which will click to the
start of the towns with that letter using index.html#A .... I am guessing
that the best way would be to simply compare the first letter of the current
town to the first letter of the previous town. However, I would also need to
put in non-clickable menu letter (i.e. there are no towns beginning with Z)


I did a similar think by feeding values from a drop down box into a query.
http://www.ckdog.co.uk/php/abstracts.php

To display all towns beginning with a certain letter, assign the output of
the drop down box to variable $letter and do this:

SELECT field1, feld2,townetc FROM tbltable WHERE town LIKE'$letter%'
$order";

The variable $order is there so that you can change how the results are
displayed. You may want to order the results on a different field, say a
date field or something.

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 16 '05 #3
elyob wrote:
That's probably a better way then using the PHP method I was thinking of,
although I would want to show a greyed out letter for the substrings that
don't exist ...

e.g. [A] [b] C [D] [E] [F] ...

So here, C is shown but has no href # as there are no towns beginning with C
..


You can create a table with all the letters and join it with the towns
table for a better approach.

select letter, count(town) from letters left join town
on letter=substring(town, 1, 1) group by letter

My test run returned something like this

letter count(town)
A 1
B 1
C 0
D 1
E 1

Now, just go through the result array
printing the link if count(town) != 0

Happy Coding :)

--
"Yes, I'm positive."
"Are you sure?"
"Help, somebody has stolen one of my electrons!"
Two atoms are talking:
Jul 16 '05 #4

"hex kid" <he****@hotpop.com> wrote in message
news:f1******************************@news.meganet news.com...
elyob wrote:
That's probably a better way then using the PHP method I was thinking of,
although I would want to show a greyed out letter for the substrings that
don't exist ...

e.g. [A] [b] C [D] [E] [F] ...

So here, C is shown but has no href # as there are no towns beginning with C..


You can create a table with all the letters and join it with the towns
table for a better approach.

select letter, count(town) from letters left join town
on letter=substring(town, 1, 1) group by letter

My test run returned something like this

letter count(town)
A 1
B 1
C 0
D 1
E 1

Now, just go through the result array
printing the link if count(town) != 0


I'm now thinking of moving away from the MySQL approach .. we run multiple
sites all using the same code. This is going to affect all the sites. Some
of the sites are UK only, although the hotel site is worldwide. This extra
table probably isn't what I need when I already hold the details.

I'm now thinking along the lines of holding an array of the standard
alphabet, and probably passing the previous first letter for comparison
purposes throughtout the 'while' loop. If the new letter's not the next
letter in the alphabet, output it, repeat until they match, then output a
link ...

I'm just trying to figure out how this is going to work ...

Thanks for your help so far ..
Nick

Jul 16 '05 #5

"elyob" <ne*********@hotmail.com> wrote in message
news:7m********************@news-text.cableinet.net...
I've got a list of towns in a MySQL database, which I currently pull from
the database ... e.g. http://www.local-hotel.com/townsall/AU/

I now want to put a [A] [b] [C] etc menu at the top, which will click to the start of the towns with that letter using index.html#A .... I am guessing
that the best way would be to simply compare the first letter of the current town to the first letter of the previous town. However, I would also need to put in non-clickable menu letter (i.e. there are no towns beginning with Z)
How'd you lot plan this simple task?


Thanks, I have it working using a simple array, php substr and html#. Not
100% finished as it shows the letters of those that have no towns with those
letters. But hey, who's picky!

The suggestions I received were extremely helpful in making my mind up on
how to do it. Once again, thanks.

Nick

Jul 16 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Enjoy Life | last post by:
We have an ASP site that hits up an Access database of categories of products and products. (e.g. Categories = Napkins, Tablecloths; Products = 20x20 Napkins, 21x21 Napkins, 54x54 Tablecloths,...
3
by: mallyonline | last post by:
Thank you for your previous help. I posted regarding listing the names of files held in a folder on the server and making the list appear clickable. This has now been accomplished. The...
3
by: filip.norrgard | last post by:
Hi All! I've been developing an ASP.Net 2.0 web application using the Visual Studio 2005 tools. Currently datagrids on a page are filled with data from a dataset (a .xsd file in the "project")...
0
by: yeahuh | last post by:
Quick and dirty version. Godaddy server using MySQL 4.0.24 I’m trying a left join to obtain id’s in table A(cars) that are NOT in car_id in table B(newspaper): *This is a cut down version...
3
by: WiseG1rly | last post by:
Hey everyone! I am completley new and I will start off by saying that I am not a programmer - figuring out this search took so long! I am debugging now and would appreciate any help :) ...
4
by: WiseG1rly | last post by:
Hey everyone! Still working on a site I posted for a while ago. Essentially I have a search function that is populated through by a database in mySQL and PHP. I need a few things to help the...
7
by: Jeff Gaines | last post by:
I have spent the day learning how to use Zend Development Environment. I can now produce a list of files in a directory, filtered by extension, and apparently clickable. Unfortunately clicking on...
3
by: crazychrisy54 | last post by:
Hi there I just wondered if there is any way using GD to insert a clickable button or some clickable text into a image? It is possible to create images for buttons but what if you want a...
221
Atli
by: Atli | last post by:
You may be wondering why you would want to put your files “into” the database, rather than just onto the file-system. Well, most of the time, you wouldn’t. In situations where your PHP application...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.