/    Sign up×
Community /Pin to ProfileBookmark

Browse database table in html?

Hi,
Suppose I have a table in a database like this:

Counrty Region Town
UK North Town 1
UK South Town 2
UK West Town 3
UK East Town 4
USA North Town 5
USA South Town 6
USA West Town 7
USA East Town 8
China North Town 9
China South Town 10
China West Town 11
China East Town 12

Does anyone know of a script which will help me take this table and produce the html to allow users to see this via a dynamic menu like this:

UK
USA
China

and then if they Click UK they would see:

North
South
East
West

and if they click North they would see:

Town 1

and if they clicked Town one that would set a variable equal to town 1?

I was trying to see if this was possible without using dropdowns. (as I’m having a lot of trouble doing it with dropdowns due to the length of the dropdowns!)

Thanks in advance!

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@DaiWelshMay 13.2004 — This can be done either server side or client side.

What I mean by that is you could show the user a page with just the first drop-down then they select from it and a second page loads with the appropriate values in the second drop-down then when they select from that a third page loads with the values for the third drop-down. This is a server-side solution because all the code would run on the server and it is good for bandwidth as you dont have to send all combinations to the client, only the ones they select, but can be a little slow after they select each item while it loads the next page.

Alternatively you can load all the combinations into a javascript array and then do a client side solution which loads the appropriate values into the select boxes in response to their selections without needing to reload a page from the server. This method can be better form a usability perspective when it works as the response is almost instant when the user makes a selection, however it relies on javascript being allowed by the browser and it requires all combinations to be sent to the user which can make the page slow to load initially and may also be an issue for security, though it does not look like this would be an issue for you.

If you decide to go with the client side solution look on script sites for a javascipt solution for 'related dropdowns' or 'related selects' or similar. If you decide to do it with PHP then we could probably help out with some pointers on the code, or again there may be some resources on script sites for it.

HTH,

Dai
Copy linkTweet thisAlerts:
@ezryderauthorMay 13.2004 — Hi Dai,

Thanks for the response. I have alreadytried the client side solution but the problem is the array output by my php is so long that it gets put onto a second line. (I really don't know why this happens) and javascript can't seem to handle these arrays which run over two lines.

So I was wondering about the server-side solution I thought it may be a common requirement so someone may know of a prewritten php script which does this function (i.e. the sql, table formatting, hyperlinking)and save me the job!
Copy linkTweet thisAlerts:
@DaiWelshMay 13.2004 — You may well have some joy finding a prebuilt one, it is certainly a common enough problem.

For the record, it would be possible to avoid the overflow problem by defining the javascript array elements in multiple lines rather than all in one line.

Sorry I dont have any script recommendations but others might...
Copy linkTweet thisAlerts:
@sherriMay 13.2004 — You could use php and get vars. Wrap your content in if statements. And make the categories into links.


Like when you click China it links to the current page with the http get var "?showchina=1".

Then in your if statement do if $HTTP_GET_VARS['showchina'] == 1 then

echo your regions. Then do this for the list of regions.

See what I mean?
×

Success!

Help @ezryder spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...