Jump to content
xisto Community
moldboy

Categories And Automatic Sorting without using SQL

Recommended Posts

Despite what you might think I don't want to have SQL involved in the solution, just a heads up.So let's say I had a page with a table and 4 rows, on each row there was a dropdown box with the options A, and B, there was also a text box, with the option to type (obvously)Now lets say I wanted the user to choose either A or B and enter a number in the box, then when they pressed submit on the next page the readout would be a: ______, and b:_____ where in the _______ there would be another number, infact the sum of the numbers on the other page. So if they choose A) 3, a) 5 A) 8 B)3 then the results would be A: 16, and B: 3. The script added the two catagories independantly. I laready know how to do input and output, just can't figure out how to tell the srcipt only to add the numbers of the individual catagories. This script would of corse need to be expanded for my purpose to hold many more numbers and several more catagories. Any thoughts?

Notice from BuffaloHELP & snlildude87:
BuffaloHELPE: Eited topic title (corrected a spelling) and added description.snlildude87: Fixed a spelling error in the title
Edited by snlildude87 (see edit history)

Share this post


Link to post
Share on other sites

You need to explain your problem a bit better.

So if they choose A) 3, a) 5 A) 8 b ) 3 then the results would be A: 16, and B: 3.  The script added the two catagories independantly.

How is it that they can choose 3 different values for A and only 1 for B?
And which is the number they're s'posed to have entered in the text box? I don't understand what you're trying to do here. :rolleyes:
I'm not too familiar with PHP syntax yet cos I usually code in ASP, but I woulda thought if you're adding the value of the dropdown to the value of what they've typed and then printing it on the next page that it would be:
value of the dropdown form variable + value of the text form variable.
That sounds pretty obvious so I'm guessing maybe you're asking something else but I can't figure that out.

Sorry for double posting but just been thinking about it a bit more and didn't notice the 4 rows in the table thing which means that there's 4 dropdowns and the values of all 4 get added together - is that right?
If that's the case you could do it one of two ways:
1. Give each dropdown the same name and then the form value would become a comma-delimited string (eg 3,5,8). Then you could split the string into an array and then add the values.
2. Give each dropdown the same name but add 01, 02, 03 to the end of the names (eg form01, form02 etc.). Then you could use a loop where your counter equals the number at the end of the form name to add the values.

Share this post


Link to post
Share on other sites

The above was just (what I thought to be) a simple example.Yes there are four rows, and in each row there is a dropdown, and a textbox. For each row the dropdown would contain A, and B. These would be the catagories. Each text box would have a number, defined by the user. Now after entering (or before) the drop down would be choosen. All the numbers assigned to catagorie A would be added, and then independantly all the numbers assigned to catagorie B would be added. In the above example there would be only number assigned with B so there would be no adding, however there are three numbers assigned to catagorie A so there would be three numbers. My question was how to add them when there would be no predefined order, like we will do all the A's and then all the B's, there could be a few A's and a few B's scatered randomly.I was asking for insight simply because I want to do something simmilar, but rather then trying to explain that project to come up with a simple one.You say that you are more into ASP, just for intrest, which would you say is better? How about learning curve?

Share this post


Link to post
Share on other sites

You say that you are more into ASP, just for intrest, which would you say is better?  How about learning curve?

I haven't done too much in depth with PHP yet but one thing I noticed pretty soon was how annoying it is if you missing out { or ; from your lines of code. It's easier to see when you've missed stuff out in ASP cos you're typing things like 'then' and 'end if' etc and the error messages tell you what's missing from the line that's wrong whereas PHP error messages tend to flow to the line where there is a closing ; or { which may not necessarily be the line that's wrong.
I have no particular allegiance to either: had to learn ASP cos that's what our company's website is hosted on.

Share this post


Link to post
Share on other sites

Tyssen, once you're familiar with the way errors are shown with PHP, php errors are just as easy to find as with ASP.net

moldboy, as youmay have noticed i sometimes have a hard time understanding your questions, but if i got this right and A only has numbers..:

<input type="text" name="first"><input type="text" name="second">
<?php$input1=$_POST['first']; $input2=$_POST['second'];$a=$input1 + $input 2;$one="0"; $two="0";if(empty($_POST['first']){ $one="0"; } else { $one++; }if(empty($_POST['second']){ $two="0"; } else {  $two++; }$b= $one + $two;echo "input sumup: $a, field sumup: $b";?>

There probably is some kind of function that makes this alot easier, foreach won't work because you will need to create an array, wich in this case is not possible i think.

Hope this helps a bit..

Share this post


Link to post
Share on other sites

Deeply sorry for the doublepost, but i want to prevent errors in that small piece of code...forgot some )'s, here the revised version :rolleyes:

<?php$input1=$_POST['first']; $input2=$_POST['second'];$a=$input1 + $input 2;$one="0"; $two="0";if(empty($_POST['first'])){ $one="0"; } else { $one++; }if(empty($_POST['second'])){ $two="0"; } else {  $two++; }$b= $one + $two;echo "input sumup: $a, field sumup: $b";?>

Once again, sorry for the doublepost...if only there was an edit button...

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.