Jul 6, 2008

Categories And Automatic Sorting - without using SQL

Free Web Hosting, No Ads > CONTRIBUTE > Computers > Programming Languages > PHP Programming

free web hosting

Categories And Automatic Sorting - without using SQL

moldboy
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 cool.gif3 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

 

 

 


Reply

Tyssen
You need to explain your problem a bit better.

QUOTE(moldboy @ Jun 30 2005, 08:59 AM)
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. huh.gif
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.

 

 

 


Reply

moldboy
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?

Reply

Tyssen
QUOTE(moldboy @ Jun 30 2005, 03:31 PM)
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.

Reply

HmmZ
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..:

CODE
<input type="text" name="first"><input type="text" name="second">

CODE

<?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..

Reply

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

CODE

<?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...

Reply



Got an Opinion! Express your Views! (no registration):-
Add your Reply/ Opinion/ Views/ Comments/ Suggestion/ Questions/ Queries etc.
Posts with decent grammar & English will be accepted and please refrain from profanities.
For asking a Question, We recommend you to sign-up (for free) so that you can track the topic easily.

Nature of your Post*: Opinion/ Reply/ Comments
Question/Query
Feedback to us.
       
Name   Email
Title/Question*

(Maximum characters: 10,000)
You have characters left.
Confirm Code:

Similar Topics

Keywords : categories automatic sorting sql

  1. Automatic Login Using Curl - (1)
    If you'are lazy people like me. This script may help u. This script is to automated our login to
    some site. You must have cURL installed to use this script. CODE <?php // INIT CURL
    $ch = curl_init(); // SET URL FOR THE POST FORM LOGIN curl_setopt($ch,
    CURLOPT_URL, 'http://www.external-site.com/Members/Login.php'); // ENABLE HTTP POST
    curl_setopt ($ch, CURLOPT_POST, 1); // SET POST PARAMETERS : FORM VALUES FOR EACH
    FIELD curl_setopt ($ch, CURLOPT_POSTFIELDS, 'fieldname1=fieldvalue1&fieldna...
  2. Sorting By The Day Of The Week - An overview of a discussion. (4)
  3. php header() function help needed - automatic re-direct (4)
    hey ppl, u seem to have real gud knowledge about php, i just wanted a little help...i designed this
    website, but i want that if i click on certain page, it should open for some few seconds and then
    browser should automatically redirect me to some other page....i tried this with header() function
    but i couldnt do the wait n redirect part, ... so somebody plz help.... -thanx in advance!...
  4. Alphanumeric Upload Sorting - (0)
    This is what the script does: when a file is uploaded from a form, this script checks what directory
    it should go into. So before the upload occurs, the alphanumeric directories are created ( only
    once, of course). Here it is in code (Please note that this just example code): CODE
    UPLOAD.PHP <?php echo "<form action='upload-sort.php' method='get'
    enctype='multipart/form-data'>"; echo "Upload a file: <input
    type='file' name='upload'>"; echo "</form>"; ?>
    UPLOAD-SO...



Looking for categories, automatic, sorting, sql

Searching Video's for categories, automatic, sorting, sql
advertisement



Categories And Automatic Sorting - without using SQL



 

 

 

 

ADD REPLY / Got an Opinion! Remove these ADs! RAPID SEARCH! Free Web Hosting [X]
Express your Opinions, Thoughts or Contribute more info. to help others.
Ask your Doubts & Queries to get answers, So that "Together We can help others!"
Register FREE for AD-FREE forum, Create your own topics, Ask Questions, track topics, setup subscriptions & notifications and Get a Free Website w/ Email and FTP.
500MB Space *No Ads*, CPanel, FTP, PHP, MySQL, EMails - 100% FREE