form sorting thru php

  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

is there a way of using php to sort the fields of the form so they go into the right mysql field. the problem i get is that i list the fields in the mysql but the results displayed dont match the field names. is this a common occurance? is there a way of combating this at all?
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Please give an example of your script that you have this prolem with.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

sorry for being vague, i have this problem. all the results go into the database fine. i have checkboxes and radio button info that i want to show. now what i have trouble with is this:

if a have a question with 3 possible answers, the user can select all or any. when the user is presented with radio buttons then the user can only select 1 answer. the tricky bit is this. i have a viewdb.php whereby i can view what the user has filed in. what i want to be able to see is what answers the user has selected whether it be a readio button or checkbox(es) against the actual question itself. so if i ask a question like: how many brothers do you have? and the selection is 1, 2, 3, 4, or more then there would be 5 checkboxes. how would i display the result so i could see the question (or the text that relates to the question since it would be a column header) and the result. how different would this be for radio buttons? if i had a question like: what colour are your eyes? 3 possible answers. black, brown, blue. how do i get the result in the viewdb.php file to show that i have chosen blue as the answer?.

what all this boils down to is this. i want to be able to display the answers in table form by pulling the answers from the database and placing them in a table.
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

So, all your trying to do is display all the answers?
If so you can do something like this, if you haven't already tried.
PHP Code: [ Select ]
$info = mysql_query("SELECT * FROM `questions`");
 
echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
 
            <tr>
 
               <td>
 
                  Username:
 
               </td>
 
               <td>
 
                  Eye Colour
 
               </td>
 
               <td>
 
                  # of Brothers
 
               </td>
 
            </tr>";
 
while($q = mysql_fetch_object($info)) {
 
   echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
 
               <tr>
 
                  <td>
 
                     $q->username
 
                  </td>
 
                  <td>
 
                    $q->eyecolor
 
                  </td>
 
                  <td>
 
                     $q->brothers
 
                  </td>
 
               </tr>";
 
}
 
echo "</table>";
  1. $info = mysql_query("SELECT * FROM `questions`");
  2.  
  3. echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  4.  
  5.             <tr>
  6.  
  7.                <td>
  8.  
  9.                   Username:
  10.  
  11.                </td>
  12.  
  13.                <td>
  14.  
  15.                   Eye Colour
  16.  
  17.                </td>
  18.  
  19.                <td>
  20.  
  21.                   # of Brothers
  22.  
  23.                </td>
  24.  
  25.             </tr>";
  26.  
  27. while($q = mysql_fetch_object($info)) {
  28.  
  29.    echo "<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
  30.  
  31.                <tr>
  32.  
  33.                   <td>
  34.  
  35.                      $q->username
  36.  
  37.                   </td>
  38.  
  39.                   <td>
  40.  
  41.                     $q->eyecolor
  42.  
  43.                   </td>
  44.  
  45.                   <td>
  46.  
  47.                      $q->brothers
  48.  
  49.                   </td>
  50.  
  51.                </tr>";
  52.  
  53. }
  54.  
  55. echo "</table>";

I think that is what your trying to do.
Hope that it helped.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

$q->username

'->' is actually allowed?
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

i have a table. in a cell i have a header of "eye colour" i have 4 possible answers so i have 4 radio buttons. is this where the value="blue" rather than value="1"
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

trouble i have is this. to read the value of a checkbox is fine because each checkbox is individual and has its own value. so to pull the checkbox out of a database isnt as much trouble as a radio button. for a radio button to work they must have the same name so that only one can be selected. but when one is selected how do i know what has been filled in when i try to display the results. if the choice is 'red', 'yellow', 'pink' or 'green' the radio button just chooses one. how do i know what has been chosen if the radion button value is '1'. can i have the radio button value be 'blue' or 'red' or 'green'. that way when the results are viewed, the right value is shown when displaying the results of a radio button
  • MasterSlowPoke
  • Newbie
  • Newbie
  • MasterSlowPoke
  • Posts: 7
  • Loc: Tampa

Post 3+ Months Ago

Code: [ Select ]
<INPUT TYPE=RADIO NAME="ecolor" VALUE="brown">etc
<INPUT TYPE=RADIO NAME="ecolor" VALUE="blue">etc
<INPUT TYPE=RADIO NAME="ecolor" VALUE="green">etc
<INPUT TYPE=RADIO NAME="ecolor" VALUE="hazel">etc
  1. <INPUT TYPE=RADIO NAME="ecolor" VALUE="brown">etc
  2. <INPUT TYPE=RADIO NAME="ecolor" VALUE="blue">etc
  3. <INPUT TYPE=RADIO NAME="ecolor" VALUE="green">etc
  4. <INPUT TYPE=RADIO NAME="ecolor" VALUE="hazel">etc
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Yes that is wha tyou should do.
  • buzzby365
  • Proficient
  • Proficient
  • buzzby365
  • Posts: 288

Post 3+ Months Ago

thanks alot people. my database works real well now. all the fields are being read into the correct spaces and pulled out in the right way also. my readio buttons have actual meaningful word values rather than just numbers. thanks for your help to all those that participated.

Post Information

  • Total Posts in this topic: 10 posts
  • Users browsing this forum: No registered users and 40 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.