Results 1 to 10 of 10
  1. #1
    Join Date
    Nov 2004
    Posts
    28

    Unanswered: Insert Data from combo box in form

    Im trying to make a simple poll. Im only gonna use it for a week or so so its not a big deal if its perfect and optimized. What i want is a simple form with 2 groups of drop down boxes (Good & Bad) that have certain data in it. The user selects from the combo box, presses submit and the data in the combo boxes is inputed in a databse. All i have so far is a database called "PHV8" with a "Poll" table. Inside the table i have the following fields. ID (Primary, auto increment). Good1, Good2, Good3, Bad1, Bad2, Bad3. After they click submit i would like it to display the top 3 choices for both the Good and the Bad sections.

    Im new to php and have no idea where to start. Any info word be appreciated.

    Thanks for your help

  2. #2
    Join Date
    Jan 2005
    Location
    Rees / Germany
    Posts
    34
    Thats very easy. Do you have any php code right now?
    Do you have any html code right now?
    If yes, can i see them? Would be nice. Otherwise contact me via e-mail so i can give you some support.
    But for now, i'll give you some links where you can find some information.

    http://www.php.net/manual/en/ref.mysql.php

    Here you can find all information you need to solve your problem. You have examples there, so it shoul be easy for you.

    http://de3.php.net/manual/en/index.php

    Here you can find a complete php manual with user comments. So it should be easy for you to find the right topic for you. Just click and go on

    If you need further help, just scream...

    regards

  3. #3
    Join Date
    Nov 2004
    Posts
    28
    here's what i came up with right now. Im using text boxes instead of combo boxes for right now. But i will eventually want to switch it over to combo boxes.
    I actually got it posting to the database which it wouldnt before. I was wondering now how to i find what the most common input is, for both the good and bad sections after you click submit. Right now after you click submit it goes to "data entered correctly"

    <?
    if(!$submit) // if no submit button has been pressed
    {
    ?>
    <form method=POST action=newtry.php>
    <input type=text name=txtGoodA>
    <input type=text name=txtGoodB>
    <input type=text name=txtGoodC>
    <input type=text name=txtGoodD>
    <input type=text name=txtGoodE>
    <input type=text name=txtBadA>
    <input type=text name=txtBadB>
    <input type=text name=txtBadC>
    <input type=text name=txtBadD>
    <input type=text name=txtBadE>
    <input type=submit name=submit value=Submit>
    <?
    } else { // if the submit button has been pressed

    $username="root";
    $password="";
    $database="vgddstev_PHV8";

    mysql_connect(localhost,$username,$password);
    mysql_select_db($database) or die( "Unable to select database");

    $sql = "INSERT INTO Choices (ID, Good1, Good2, Good3, Good4, Good5, Bad1, Bad2, Bad3, Bad4, Bad5)
    VALUES ('','$txtGoodA','$txtGoodB','$txtGoodC','$txtGoodD ','$txtGoodE','$txtBadA','$txtBadB','$txtBadC','$t xtBadD','$txtBadE')";

    $result = mysql_query($sql);
    mysql_close();
    echo "Data was entered correctly!";
    }
    ?>

  4. #4
    Join Date
    Jan 2005
    Location
    Rees / Germany
    Posts
    34
    To find out wht the most common input is, just enter a sql query...

    $query = "SELECT * FROM table WHERE good1 = xyz";
    $result = mysql_query( $query );
    $num = mysql_num_rows( $result );

    $num contains now the number of matches the sql statement found in the table.
    I hope, thats what you wanted to know, i'm not sure because my english is not that good...

    Regards

  5. #5
    Join Date
    Nov 2004
    Posts
    28
    That's sort of what i wanted. Except i want it to look up the Top 5 matches. Based on how many occurances of it are in the DB. everytime someone selects "abc" from the list box "abc" gets inserted into the database. Now i want to see what objects has the most occurances

  6. #6
    Join Date
    Jan 2005
    Location
    Rees / Germany
    Posts
    34
    Maybe this link will help you:
    http://dev.mysql.com/doc/mysql/en/Counting_rows.html

    Just enter the correct sql query to your php code.
    Than use a switch or if enquiry to get your top 5!

    I hope that will help you. Or, maybe, try to explain your problem in another way, so that i could understand you correctly...

    regards

  7. #7
    Join Date
    Nov 2004
    Location
    out on a limb
    Posts
    13,692
    Provided Answers: 59
    If you are designing a survey / questionaire you may want to consider storing the reults to the questions in a another table linked on the SurveyID, with a prime key of SurveyID & QuestionID. However if it is truly a short term 'quick & dirty' app then it proably wont matter that much.

  8. #8
    Join Date
    Jan 2005
    Location
    Rees / Germany
    Posts
    34
    Quote Originally Posted by healdem
    If you are designing a survey / questionaire you may want to consider storing the reults to the questions in a another table linked on the SurveyID, with a prime key of SurveyID & QuestionID. However if it is truly a short term 'quick & dirty' app then it proably wont matter that much.
    I see no sense in the use of two tables. Sorry.

  9. #9
    Join Date
    Nov 2004
    Posts
    28
    i'll try to explain it better. Lets say the user has 5 drop down boxes. In those 5 boxes there is the same 10 choices. The user picks his favortie 5 and select them using the 5 given drop down boxes. Lets say the 10 choices are A,B,C,D,E,F,G,H,I,J .

    I have my Choices table with the following fields. (the 5 drop down boxes correspond with 1 through 5) ID is a auto increment primary key.
    Im also filling in some random data to use as an example

    ID 1 2 3 4 5
    1 B A G I J
    2 G H A B I
    3 G C D H A

    what i want is to count up the total votes for A,B,C,D,E,F,G,H,I,J and display the top 5 on the page after i submit the inputs. So in this example the next page would say something like this:

    Top 3 votes
    G with 3 votes
    A with 3 votes
    B with 2 votes


    Now a user doesnt have to put data into all 5. If they omit a drop down box a 0 is put into the table. So i do not want to count 0's in the count. Hopefully that clears up the confusion. Thanks all for the extremely quick responses!!
    Last edited by johnnysc; 01-20-05 at 18:50.

  10. #10
    Join Date
    Jan 2005
    Location
    Rees / Germany
    Posts
    34
    Ok... now, i know what you want
    Make a loop. Count the number of entrys for each value you want.
    Store the results into an array. Then just sort the array how you like it. From one to ten or whatever. If all values are sorted it's very easy for you to print the values to the browser
    Ich really hope you understand what's in my mind
    If you have further questions, i will try to help you!


    regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •