示例#1
0
/** Prints the number of people that have responded to the poll */
function numberOfRespondents()
{
    connect();
    $q = "SELECT * FROM " . RESULTS_TABLE;
    $result = mysql_query($q) or mysql_err($q);
    print mysql_num_rows($result);
    disconnect();
}
示例#2
0
/**
 * Prints out the questions editor, with all of the databases's 
 * current data loaded into it.
 */
function printQuestionsEditor()
{
    $link = connect();
    $q = "SELECT * FROM " . QUESTIONS_TABLE;
    $result = mysql_query($q) or mysql_err($q);
    while ($row = mysql_fetch_array($result)) {
        printEditor($row);
    }
}
示例#3
0
<?php

/** Simple helper script to setup the databases, could allow usernames, etc later */
include "database_helper.php";
connect();
/** Very simple setup script */
$q = "DROP TABLE IF EXISTS " . RESULTS_TABLE;
$r = mysql_query($q) or mysql_err($q);
$q = "DROP TABLE IF EXISTS " . QUESTIONS_TABLE;
$r = mysql_query($q) or mysql_err($q);
$q = "CREATE TABLE " . QUESTIONS_TABLE . "(id INT NOT NULL AUTO_INCREMENT," . "PRIMARY KEY(id)," . "type INT, content TEXT, opts TEXT)";
$r = mysql_query($q) or mysql_err($q);
disconnect();
?>

<h1>Databases created successfully!</h1>
示例#4
0
/** 
 * Process Questions
 */
function processResults()
{
    connect();
    // Loop through the dynamic fields
    $q = "SELECT * FROM " . QUESTIONS_TABLE;
    $result = mysql_query($q) or mysql_err($q);
    // store the column names, and their answers
    $qResults = array();
    while ($row = mysql_fetch_array($result)) {
        $id = $row['id'];
        $name = "question" . $id;
        $content = $row["content"];
        $r = "";
        switch ($row["type"]) {
            // multiple check boxes are a pain in the ass.
            case Q_MULTI:
                $opts = explode(",", $row['opts']);
                foreach ($opts as $opt) {
                    //If the value is set, then it was checked
                    if (isset($_POST[$name . $opt])) {
                        $r = $r . $opt . ",";
                    }
                }
                break;
                // everything else can use a standard case
            // everything else can use a standard case
            default:
                // try to gather the result for the question
                $r = mysql_real_escape_string($_POST[$name]);
                break;
        }
        print "<p><strong>{$content}</strong><br/>{$r}</p>";
        $qResults[$name] = $r;
    }
    // end while
    $cols = "";
    $values = "";
    foreach ($qResults as $key => $val) {
        $cols = $cols . $key . ",";
        $values = $values . "'" . $val . "'" . ",";
    }
    $cols = rtrim($cols, ",");
    $values = rtrim($values, ",");
    // Gaurd against SQL injection atttacks
    $q = sprintf("INSERT into %s (%s) VALUES(%s)", RESULTS_TABLE, $cols, $values);
    $result = mysql_query($q) or mysql_err($q);
    disconnect();
}
示例#5
0
            $de_course2 = "Onsite";
            break;
        case 43:
            $de_course = "Resident  Onsite";
            $de_course2 = "Onsite";
            break;
        default:
            $de_course = "";
            $de_course2 = "Onsite";
    }
}
if (strlen($lastname) > 0 && strlen($firstname) > 0) {
    $str = ' SELECT *
             FROM `cleft_register`
             WHERE    lastname="' . $lastname . '"  AND firstname="' . $firstname . '"   ;    ';
    $query = mysql_query($str) or die(mysql_err());
    $check = mysql_num_rows($query);
    if ($check > 0) {
        while ($r = mysql_fetch_row($query)) {
            $title = $r[1];
            switch ($title) {
                case 1:
                    $detail_title = "Mr.";
                    break;
                case 2:
                    $detail_title = "Miss";
                    break;
                case 3:
                    $detail_title = "Mrs.";
                    break;
            }