0

我有这个代码。

 $correct_spot = rand(1,10);
 $data = array(
                    'current_correct_answer' => $correct_spot                   
                );



                $this->db->update('demo_user_profiles', $data, array('upro_id' => $user_id));

                $query = $this->db->get_where('demo_user_profiles', array('upro_id' => $user_id));
                $result = $query->result();
                print_r($result);

在这个页面上,$correct_spot 编号被打印出来,插入,然后检索和重新打印。一切正常。但是,如果我在 PHPmyadmin 中查看 $correct_spot 有时会有错误的值,就好像它再次评估整个事情一样。这是一个问题,因为当我在另一个页面上检索值时,它与我输入的值不同。我做错了什么吗?MySQL 字段只是一个 int(11)。

提前致谢。

相关控制器代码用于“问题”

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Site extends CI_Controller {

/**
 * Index Page for this controller.
 *
 * Maps to the following URL
 *      http://example.com/index.php/welcome
 *  - or -  
 *      http://example.com/index.php/welcome/index
 *  - or -
 * Since this controller is set as the default controller in 
 * config/routes.php, it's displayed at http://example.com/
 *
 * So any other public methods not prefixed with an underscore will
 * map to /index.php/welcome/<method_name>
 * @see http://codeigniter.com/user_guide/general/urls.html
 */

function __construct()
{
    parent::__construct();

    // To load the CI benchmark and memory usage profiler - set 1==1.
    if (1==2)
    {
        $sections = array(
            'benchmarks' => TRUE, 'memory_usage' => TRUE,
            'config' => FALSE, 'controller_info' => FALSE, 'get' => FALSE, 'post' => FALSE, 'queries' => FALSE,
            'uri_string' => FALSE, 'http_headers' => FALSE, 'session_data' => FALSE
        );
        $this->output->set_profiler_sections($sections);
        $this->output->enable_profiler(TRUE);
    }

    // Load required CI libraries and helpers.
    $this->load->database();
    $this->load->library('session');
    $this->load->helper('url');
    $this->load->helper('form');

    // IMPORTANT! This global must be defined BEFORE the flexi auth library is loaded!
    // It is used as a global that is accessible via both models and both libraries, without it, flexi auth will not work.
    $this->auth = new stdClass;

    // Load 'standard' flexi auth library by default.
    $this->load->library('flexi_auth');

    // Check user is logged in via either password or 'Remember me'.
    // Note: Allow access to logged out users that are attempting to validate a change of their email address via the 'update_email' page/method.
    if (! $this->flexi_auth->is_logged_in() && $this->uri->segment(2) != 'update_email')
    {
        // Set a custom error message.
        $this->flexi_auth->set_error_message('You must login to access this area.', TRUE);
        $this->session->set_flashdata('message', $this->flexi_auth->get_messages());
        redirect('auth');
    }

    // Note: This is only included to create base urls for purposes of this demo only and are not necessarily considered as 'Best practice'.
    $this->load->vars('base_url', 'http://cloudtute.com/');
    $this->load->vars('includes_dir', 'http://cloudtute.com/includes/');
    $this->load->vars('current_url', $this->uri->uri_to_assoc(1));

    // Define a global variable to store data that is then used by the end view page.
    $this->data = null;
}

public function index()
{
    $this->load->view('home');
}

function dashboard()
{
    // Get any status message that may have been set.
    $this->data['message'] = $this->session->flashdata('message');

    $this->load->view('dashboard', $this->data);
}

function question()
{
    // Get any status message that may have been set.
    $this->data['message'] = $this->session->flashdata('message');

    $this->load->view('question', $this->data);
}

function answer()
{
    // Get any status message that may have been set.
    $this->data['message'] = $this->session->flashdata('message');

    //Get question answer
    $username = $this->input->post("variable_serial");
    $this->data['questiontest']=$username;

    $question_id = $this->input->post("question_id");
    $this->data['question_id'] = $question_id;


    $this->load->view('answer', $this->data);
}




function elements()
{
    // Get any status message that may have been set.
    $this->data['message'] = $this->session->flashdata('message');

    $this->load->view('elements', $this->data);
}

}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

标头代码:

<?php
/**
 * Created by JetBrains PhpStorm.
 * User: Randy
 * Date: 29/04/13
 * Time: 13:37
 * To change this template use File | Settings | File Templates.
 */

?>

<!DOCTYPE html>
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7" lang="en"> <![endif]-->
<!--[if (IE 7)&!(IEMobile)]><html class="no-js lt-ie9 lt-ie8" lang="en"><![endif]-->
<!--[if (IE 8)&!(IEMobile)]><html class="no-js lt-ie9" lang="en"><![endif]-->
<!--[if (IE 9)]><html class="no-js ie9" lang="en"><![endif]-->
<!--[if gt IE 8]><!--> <html lang="en-US"> <!--<![endif]-->
<head>

    <!-- Meta Tags -->
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

    <title>Ace HSC Maths</title>

    <meta name="description" content="" />

    <!-- Mobile Specifics -->
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="HandheldFriendly" content="true"/>
    <meta name="MobileOptimized" content="320"/>

    <!-- Mobile Internet Explorer ClearType Technology -->
    <!--[if IEMobile]>  <meta http-equiv="cleartype" content="on">  <![endif]-->

    <!-- Standard Bootstrap -->


    <!-- Standard Bootstrap -->


    <!-- Bootstrap -->
    <link href="<?php echo asset_url();?>css/bootstrap.min.css" rel="stylesheet">

    <!-- Revolution Slider -->
    <link href="<?php echo asset_url();?>rs-plugin/css/settings.css" rel="stylesheet">

    <!-- Main Style -->
    <link href="<?php echo asset_url();?>css/main.css" rel="stylesheet">

    <!-- FancyBox -->
    <link href="<?php echo asset_url();?>css/fancybox/jquery.fancybox.css" rel="stylesheet">

    <!-- Font Icons -->
    <link href="<?php echo asset_url();?>css/fonts.css" rel="stylesheet">

    <!-- Shortcodes -->
    <link href="<?php echo asset_url();?>/css/shortcodes.css" rel="stylesheet">

    <!-- Responsive -->
    <link href="<?php echo asset_url();?>/css/responsive.css" rel="stylesheet">

    <!-- Custom CSS -->
    <link href="<?php echo asset_url();?>/css/custom.css" rel="stylesheet">

    <!-- Google Font -->
    <link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic,800,800italic' rel='stylesheet' type='text/css'>

    <!-- Fav Icon -->
    <link rel="shortcut icon" href="#">

    <link rel="apple-touch-icon" href="#">
    <link rel="apple-touch-icon" sizes="114x114" href="#">
    <link rel="apple-touch-icon" sizes="72x72" href="#">
    <link rel="apple-touch-icon" sizes="144x144" href="#">

    <!-- Modernizr -->
    <script src="<?php echo asset_url();?>/js/modernizr.js"></script>

    <!-- Analytics -->
    <script type="text/javascript">
        var _gaq = _gaq || [];
        _gaq.push(['_setAccount', 'Replace Your Analytics Code']);
        _gaq.push(['_trackPageview']);

        (function() {
            var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
            ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
            var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
        })();
    </script>
    <!-- End Analytics -->

    <!-- Highcharts
   ================================================== -->

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
    <script src="http://code.highcharts.com/highcharts.js"></script>




    <!--new Mathjax stuff-->
    <style>
        .MathJax_Display .MathJax,
        DIV.MathJax_MathML math,
        .MathJax_SVG_Display .MathJax_SVG {
            display: inline-block ! important;
            background-color: #ffffff;
            padding: 10px ! important;
            border: 0px dashed white ! important;
        }
    </style>

    <script type="text/x-mathjax-config">
        MathJax.Hub.Config(
        {
        tex2jax:
        {inlineMath: [['%%%%','%%%%'], ['??','??']],
        displayMath: [ ['$$','$$'], ['@@', '@@']]
        }
        }
        );
    </script>

    <script type="text/javascript"
            src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
    </script>

    <!--new Mathjax stuff-->

    <script type="text/javascript">
        $(document).ready(function() {
            Highcharts.setOptions({
                chart: {
                   // backgroundColor: {
                   //     linearGradient: [0, 0, 500, 500],
                   //     stops: [
                   //         [0, 'rgb(213, 211, 206)'],
                   //         [1, 'rgb(213, 211, 206)']
                   //     ]
                   // },
                    borderWidth: 0,
                    //plotBackgroundColor: 'rgb(124, 143, 125)',
                    plotShadow: false,
                    plotBorderWidth: 0
                },

                credits: {
                    enabled: false
                },

                colors: [
                    '#323A45',
                    '#E41B17',
                    '#FF8330',
                    '#8bbc21',
                    '#910000',
                    '#1aadce',
                    '#492970',
                    '#f28f43',
                    '#77a1e5',
                    '#c42525',
                    '#a6c96a'
                ]
            });
            var chart1 = new Highcharts.Chart({
                chart: {
                    renderTo: 'dashboardchart',
                    type: 'spline'
                },
                title: {
                    text: ''
                },
                plotOptions: {
                    series: {
                        lineWidth: 5,
                        marker: {
                            fillColor: '#FFFFFF',
                            lineWidth: 2,
                            radius: 6,
                            lineColor: null // inherit from series
                        }
                    }
                },
                subtitle: {
                    text: ''
                },
                xAxis: {
                    type: 'datetime',
                    dateTimeLabelFormats: { // don't display the dummy year
                        month: '%e %b',
                        year: '%b'
                    }
                },
                yAxis: {
                    title: {
                        text: 'Ability Score (out of 100)',
                        style: {
                            color: '#323A45',
                            fontWeight: 'bold'
                        }
                    },
                    min: 0
                },
                tooltip: {
                    formatter: function() {
                        return '<b>'+ this.series.name +'</b><br/>'+
                            Highcharts.dateFormat('%e %b', this.x) +': '+ this.y;
                    }
                },

                series: [{
                    name: 'Overall Ability',
                    // Define the data points. All series have a dummy year
                    // of 1970/71 in order to be compared on the same x axis. Note
                    // that in JavaScript, months start at 0 for January, 1 for February etc.
                    data: [
                        [Date.UTC(2013,  0,  1), 50.0],
                        [Date.UTC(2013,  0, 10), 51.2],
                        [Date.UTC(2013,  2, 12), 63.0],
                        [Date.UTC(2013,  3,  1), 59.0],
                        [Date.UTC(2013,  3, 10), 58.2],
                        [Date.UTC(2013,  3, 18), 57.0],
                        [Date.UTC(2013,  3, 28), 62.0],
                        [Date.UTC(2013,  4, 11), 67.0],
                        [Date.UTC(2013,  5,  1), 72.0],
                        [Date.UTC(2013,  5, 20), 84.0],
                        [Date.UTC(2013,  6, 13), 82.0],
                    ]

                }, {
                    name: 'Target',
                    data: [
                        [Date.UTC(2013,  0,  1), 80.0],
                        [Date.UTC(2013,  1,  1), 80.0],
                        [Date.UTC(2013,  2,  1), 80.0],
                        [Date.UTC(2013,  3,  1), 80.0],
                        [Date.UTC(2013,  4,  1), 80.0],
                        [Date.UTC(2013,  5,  1), 80.0],
                        [Date.UTC(2013,  6,  1), 80.0],
                        [Date.UTC(2013,  7,  1), 80.0]
                    ],
                    dashStyle: 'longdash',
                    marker: {
                        enabled: false
                    }
                }]

            });
        });
    </script>


</head>




<body>

<!-- Header -->
<header>
    <div class="container">
        <div class="row">
            <div class="span3">
                <div id="logo">
                    <a href="index.html" title="Ace HSC Maths"><font color="#E41B17">A<sup>+</sup></font>ce HSC Maths</a>
                </div>
            </div>

            <div class="span9">
                <!-- Mobile Menu -->
                <a id="mobile-nav" class="menu-nav" href="#menu-nav"><span class="menu-icon"></span></a>

                <!-- Standard Menu -->
                <nav id="menu">
                    <ul id="menu-nav">
                        <li><a href="http://www.cloudtute.com">Home</a></li>
                        <li><a href="elements.html">Features</a>
                            <ul class="sub-menu arrow-up">
                                <li><a href="full-width.html">Full Width</a></li>
                                <li><a href="about.html">About Us</a></li>
                                <li><a href="team.html">Our Team</a></li>
                                <li><a href="elements.html">Elements</a></li>
                                <li><a href="typography.html">Typography</a></li>
                                <li><a href="retina-icons.html">Retina Icons</a></li>
                                <li><a href="footer-widgets.html">Footer Widgets</a></li>
                            </ul>
                        </li>

                        <li><a href="http://www.cloudtute.com/auth/"><i style ="margin-top: 3px" class="icon-user icon-white"></i> Not Logged In</a>
                            <ul class="sub-menu arrow-up">
                                <li><a href="full-width.html">Full Width</a></li>
                                <li><a href="about.html">About Us</a></li>
                                <li><a href="team.html">Our Team</a></li>
                                <li><a href="elements.html">Elements</a></li>
                                <li><a href="typography.html">Typography</a></li>
                                <li><a href="retina-icons.html">Retina Icons</a></li>
                                <li><a href="footer-widgets.html">Footer Widgets</a></li>
                            </ul>

                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</header>
<!-- End Header -->
4

0 回答 0