Jump to content
Larry Ullman's Book Forums

Recommended Posts

I'm trying to figure out how one would construct an HTML form that is complex. This is best illustrated by example:

 

Suppose I want to ask you what brand of skis you own. The choices might be:

Brand1

Brand2

Brand3

etc.

 

Based on the Brand you select, I want to know what model you have:

Model1

Model2

Model3

etc.

 

There may be many brands and many models. So if you choose Brand1, I don't want you to have to look at the Models for the other brands. So, I guess, I must be looking for some kind of tree architecture.

 

I've got two of Larry's books, PHP 5 - MySQL6 and Effortless e-commerce - but I didn't see any references to this

 

Any suggestions on where to go from here?

 

thanks,

chop

Share this post


Link to post
Share on other sites

Hi Chop,

 

I think if you want to do it in 1 fell swoop, where the selection of 1 category then leads to only models relating to the chosen category? I think you would have to encorparate some javascript into the matter.

 

Otherwise I think you would have to send the results of the 1st part of the form to a page that then filters the results options shown in the next part of the form, using the information submitted from the 1st part of the form. (If that makes sense)

 

I'm going to have a look into it for you though

  • Upvote 1

Share this post


Link to post
Share on other sites

Yes, I understand that. To complicate things, I need for the user to be able to back up in the process to a given point and to continue from there -without having to start all over again.

Share this post


Link to post
Share on other sites

chop, there are a couple of things you can do. Assuming that you're grabbing the info from a database, you'll need PHP. However, in order to actually update the second box on the fly based on the first box, Jonathon is right, you will need JavaScript.

 

You could either load all the info, and store it in a variable for JavaScript to use when the page is loaded, or you could make an Ajax call when an item is selected from the first list. It's your choice.

 

Feel free to ask for more information, if you need it.

 

Edit: I should add that even if you decide to grab all the data on the page load, you should still probably use Ajax to get the data.

  • Upvote 1

Share this post


Link to post
Share on other sites

Do you think there might be some code available for this that uses some sort of tree structure? Javascript perhaps. I'm not a Javascript programmer and would rather just purchase code or a web service rather than the time to develop this. This is actually for a ski-swap application where people have to input what they have for equipment: Alpine skis | what make of ski | what model | how long etc. It's very complicated and my brain is hurting from it. I realize the digression that might result here and won't go on forever. I am getting some good information from you though. thank you

 

chop

Share this post


Link to post
Share on other sites

I don't know of any off the top of my head, but that certainly doesn't mean they don't exist. Tell ya what though, as a challenge to myself, if you want to send me the structure of your database, I'll write some code for you and send it back. I'm thinking the best approach is to grab all the data on page load (since there probably isn't that much), and then store it in a JavaScript object for later use.

 

Also, what's your time frame on this? Based on that, I can take the time to help explain things to you.

 

My email address is hartley.84@gmail.com, if you're interested.

  • Upvote 1

Share this post


Link to post
Share on other sites

How about making a drop down list for each brand? This is just me thinking. You wouldn't have to use javaScript then. The three level design is not that hard really. Larry is explaining how to this this in his PHP Advanced book. I will explain briefly.

 

You need a database, or file system, that allows for this hierarchy. It's not really that hard.

 

brands: (brand_id, brand_name)

products: (product_id, product_name)

three: (brand_id, product_id)

 

SELECT a.brand_name as brand, b.product_name as product

FROM brands as a, products as b
INNER JOIN three as c on (a.brand_id = c.brand_id)
INNER JOIN three as d on (b.product_id = d.product_id)

ORDER BY a.brand_name, b.product_name

 

I've had a few beers, so I can't GUARANTEE you this query will work. What you do here is to make different tables for brands and products. That will allow you to create brands and products as time goes. Underlined text are primary keys.

 

In this query, you join the three tables on brand_id and product_id. You can echo this information using "brand" and "product" after a loop or foreach statement. The query is also ordering the results after the brand name first, then the product names, alphabetically.

 

As for the PHP, it's another question. Have to get some sleep now. Will pick up on this if you still struggle.

 

Edit: On afterthought, you don't need JavaScript. Find a drop down hover menu. Only display the brand names in a list, and display the different products as you hover over them. There are many different existing menus that do this for you. I don't know how many products you need to display, but this might be an easy fix. :)

Edited by Antonio Conte
  • Upvote 1

Share this post


Link to post
Share on other sites

Lots to think about here! (HartlySan) I don't have the full database structure yet, only part of it as a way to begin to think about how to do this. I will be using information from the skiSwap DB to populate my form BUT, I am told that I will not be reading and writing directly to the SQL database from my form page. Rather I will be interacting via a web service that somebody else is now putting together. The SQL guy hands off some stored procedures to the web service guy, he writes the service which I, the form guy, then consumes. This is almost all new to me. I'm getting too old for this :)

 

I suppose if someone wanted to play with this you could make up any scenario of branching items and put them in an array.

 

Thanks, Antonio, for the tip on Larry's advanced PHP book. I will study what you've written and see how it works.

 

Thanks for all the help...

 

That which doesn't kill us makes us stronger .

Nietzsche

 

chop

Share this post


Link to post
Share on other sites

chop, interesting process you gotta deal with there. If you wanna go Antonio's route, certainly, that wouldn't be bad. If you still wanna go the Ajax route though, I don't mind helping.

 

In order to do that though, you'll have to give us some idea of how you're planning on making the form interact with the database (as your situation is rather unusual, I think).

  • Upvote 1

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...