Page 1 of 1

looking for direction and advice

Posted: Wed Mar 10, 2010 10:55 am
by 5Systems
Hello everyone,

I am looking for some direction and advice. I am working on a personal project to build my PHP skills, and what I am trying to do is simply create a form that pulls its data from a mySQL table, the user then inputs info and submits it to the database, simple enough, sure, but I would like to do it with loops.

I have a PHP document that builds a table called "critique_instructor" submits some questions to a database called "critique"
I have a separate PHP document that pulls those questions from the database using a loop. I also have a dropdown box to select a value.

I am looking for direction on how to go about inputing the values the user selects from the drop down that is associated with each question into my database.

I am also looking for advice if you guys think this is the correct way to go about doing it?

here is my PHP code:

Code: Select all

 
<?php
//Make a MySQL Connection
    mysql_connect("localhost", "root") or die(mysql_error());
    mysql_select_db("critique") or die(mysql_error());
 
    // Get all the data from the "critique_instructor" table
        $result = mysql_query("SELECT * FROM critique_instructor") or die(mysql_error());  
?>
 
<html>
    <head>
        <title>
            Student Critique
        </title>
    </head>
    
    <body>
        <?php echo '<h1>STUDENT CRITIQUE</h1>'; ?>
        <br>
        
        <?php echo 'In order to provide thorough training, we need your honest opinion about the training you are receiving. It 
        is not necessary to sign your name and in no way will your answers here reflect in your final grade. Your 
        frank and honest answers below will help us improve.'?>
        
        <p><?php echo '<u>Part 1 – Your instructor</u>'?>
        
        <p><?php echo 'Please rate each statement from 1 to 5, based on the following scale.'?>
        
        <p><?php echo "5………Excellent 4………Good 3………Average 2………Below Average 1………Poor"?>
        
        <form action="process.php" method="post">
            
            <!--keeps getting the next row until there are no more to get-->
            <?php while($row = mysql_fetch_array( $result )) {?>
                    <?php echo $row['id']." - ".$row['critique_question'];?>
                    
                    <select name="rating">
                        <option>5 Excellent</option>
                        <option>4 Good</option>
                        <option>3 Average</option>
                        <option>2 Below Average</option>
                        <option>1 Poor</option>
                        </select>
                     <br>
            <?php } ?>
            
 
            Use this space for any additional comments or special questions:<br>
            <textarea name="additinal_comments" rows="5" wrap="physical">
                Enter Comments Here
            </textarea>
            
            <p><input type="submit">
            
            
            
        </form>
    
    </body>
 
</html>
 
Thanks

Re: looking for direction and advice

Posted: Wed Mar 10, 2010 1:33 pm
by AbraCadaver
You can build an array of ratings so that you know what rating belongs to which question:

Code: Select all

<select name="rating[<?php echo $row['id']; ?>]">
Then when submitted, loop through the ratings and insert them:

Code: Select all

foreach($_POST['rating'] as $id => $rating) {
   //INSERT INTO table_name (id, rating) VALUES($id, $rating)
}

Re: looking for direction and advice

Posted: Wed Mar 10, 2010 4:16 pm
by mikosiko
5Systems wrote:....
I am also looking for advice if you guys think this is the correct way to go about doing it?

here is my PHP code:

Code: Select all

 
<?php
....
    <body>
[color=#FF0000]        <?php echo '<h1>STUDENT CRITIQUE</h1>'; ?>[/color]
        <br>
        
 [color=#FF0000]       <?php echo 'In order to provide thorough training, we need your honest opinion about the training you are receiving. It 
        is not necessary to sign your name and in no way will your answers here reflect in your final grade. Your 
        frank and honest answers below will help us improve.'?>[/color]
        
 [color=#FF0000]       <p><?php echo '<u>Part 1 – Your instructor</u>'?>[/color]
        
 [color=#FF0000]       <p><?php echo 'Please rate each statement from 1 to 5, based on the following scale.'?>[/color]
        
  [color=#FF0000]      <p><?php echo "5………Excellent 4………Good 3………Average 2………Below Average 1………Poor"?[/color]>
        
        <form action="process.php" method="post">
  .....  
    </body>
 
</html>
 
Thanks
I have a comment... why are you using php tags in the code ^^^ marked in red?... that is simple html code, therefore is not necessary to use php to display it.... that is a simple mistake... don't use php where you really don't need it.

Miko

Re: looking for direction and advice

Posted: Fri Mar 12, 2010 12:17 pm
by 5Systems
thanks guys I will give that a shot.