Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Updating Answer

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Updating Answer

    candidates_answer.php
    PHP Code:
    <?php

    // Last Modified 15th August 2007

    include('../config/db.php'); // Includes Database
    include('../lib/functions.php'); // Load all functions from Library

    include('templates/select_candidates.php'); // Select candidate template

    $selected_candidate sql_safe($_GET['candidates']); // Gets candidate
    echo "<h1>Questions and their answers of the candidate <u>".$selected_candidate."</u></h1>";

    $sql mysql_query("SELECT c.*, q.*, a.* FROM (( answers a LEFT JOIN candidates c ON a.candidate_id = c.id ) LEFT JOIN questions q ON a.question_id = q.id ) WHERE c.name = '$selected_candidate'"); // Query for linking table

    while($row mysql_fetch_array($sql)){
        
    $question $row['question'];
        
    $qID $row['question_id'];
        
    $answer $row['answer'];
        if(
    $answer == 1){
        
    $answer "For";
        }
        else{
        
    $answer 'Against';
        }
        
    $change_opinion "Test";
        echo 
    $question." - <b><u>Current Answer:</u> ".$answer."</b>";
        echo 
    "<br/>";

    };

    mysql_close(); // Closes DB connection

    ?>
    select_candidate.php
    PHP Code:
    <?php

    // Last Modified 14th August 2007

    $sql mysql_query('SELECT name FROM candidates');
    ?>
    <form action="<?php $_SERVER['PHP_SELF'?>" method="get">
    <select name="candidates">

    <?php
    while($row mysql_fetch_array($sql)){
    ?>

    <option><?php echo $row['name']; ?></option>

    <?php

    }
    ?>
        
    </select>
    <input type="submit" value="Find Candidate">
    </form>
    Above code is used to get the answer of the particular question from the answers table. Answer is in boolean form that is true(1) or false(2). I want to add more functionality to the script, how would I go and add a change opinion button to each answer. On click change the answer of the particular question to 1 if it's 2 and change it to 2 if it's 1?

  • #2
    New Coder
    Join Date
    Feb 2007
    Location
    Near Belfast
    Posts
    38
    Thanks
    0
    Thanked 1 Time in 1 Post
    if your site has a member system, and assuming your database of answers has a memberid slot in it (which it probibly should so that a user can't enter answers more than once), simply extract the users id (eg. $userid), and run a sql update on the answers table WHERE the user id is (eg. $userid)
    Knowledge is only half the value of passion. But passion doesn't pay the bills.

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by pemcconnell View Post
    if your site has a member system, and assuming your database of answers has a memberid slot in it (which it probibly should so that a user can't enter answers more than once), simply extract the users id (eg. $userid), and run a sql update on the answers table WHERE the user id is (eg. $userid)
    Can you elaborate a bit more?


  •  

    Posting Permissions

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