获取特定信息取决于用户登录 jquery 移动版


Get specific information depends user logged in jquery mobile

我正在开发一个jquery移动应用程序,它使用php从数据库中获取信息(例如用户登录)。 但我有这个问题: 我需要根据登录的用户显示数据库中的特定信息(客户端和项目通过客户端中的"项目"字段和项目中的"id"相互关联)

我试图将字段"项目"添加到"登录"查询中,但是当我这样做时,应用程序无法记录

提前感谢您的帮助

-----------指数.html --------------

<!DOCTYPE html>
<html>
<head>
<title>Home</title>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0"/>
<link rel="stylesheet" href="theme/css/jquery.mobile.min.css" />
<link rel="stylesheet" href="theme/css/surinteractive.min.css" />
<link rel="stylesheet" href="theme/css/jquery.mobile.icons.min.css" />
<script src="https://code.jquery.com/jquery-2.1.1.min.js"></script>    
<script src="//ajax.googleapis.com/ajax/libs/jquerymobile/1.4.3/jquery.mobile.min.js"></script>
<script src="js/json.js"></script>
</head>
<body>
<div data-role="page" id="login" data-theme="a">
<header data-role="header" data-position="fixed">
    <h1>Sistema de gesti&oacute;n de Requerimientos</h1>
</header>  
<div data-role="content">
    <div id="fm">
        <form id="form">
            <label for="username">User:</label>
            <input type="text" value="" name="username" id="username"/>
            <label for="password">Pass:</label>
            <input type="password" value="" name="password" id="password"/>  
            <a data-role="button" id="login-button" data-theme="a" class="ui-btn-icon-right ui-icon-plus ui-btn-b">
                Sign in
            </a>
        </form>       
    </div>
</div>    
<footer data-role="footer" data-position="fixed" id="footer">
    <p>&copy; Copyright 2014 </p>
</footer>   
</div>
<div data-role="page" id="menu" data-theme="a">
<header data-role="header" data-position="fixed">
    <a href="#login" data-transition="slide" data-role="button" class="b_nuevo">Back</a>
            <h3>Bugs List</h3>
</header>
<div data-role="content">
    <h3>Welcome: </h3>
    <ul data-role="listview" data-inset="true">
         <li><a href="bugs/errors.html" data-transition="slide">Create a bug</a></li>
         <li><a href="enh/enhacements.html" data-transition="slide">Create an enhacement</a></li>
    </ul>      
</div>
<footer data-role="footer" data-position="fixed" id="footer">
    <p>&copy; Copyright 2014</p>
</footer>
</div> 
</body>
</html>

------------------ json.js --------------------------

$(document).on('pagebeforeshow', '#login', function(){ 

$('#login-button').on('click', function(){

    if($('#username').val().length > 0 && $('#password').val().length > 0){

        userObject.username = $('#username').val(); 
        userObject.password = $('#password').val();

        var outputJSON = JSON.stringify(userObject);

        ajax.sendRequest({action : 'login', outputJSON : outputJSON});
    } else {
        alert('Please fill all requested information');
    }
});    
});

var ajax = {
sendRequest:function(save_data){
    var address = null;
    //address = 'http://127.0.0.1/app/inc/userValidation.php?jsoncallback=?';
    $.ajax({url: address,
        crossDomain: true,
        data: save_data,
        async: true,
        beforeSend: function() {
            // This callback function will trigger before data is sent
            $.mobile.loading('show', {theme:"a", text:"Initializing...", textonly:true, textVisible: true});
        },
        complete: function() {
            // This callback function will trigger on data sent/received complete
            $.mobile.loading('hide');
        },
        success: function (result) {
            if(result == "true") {
                $.mobile.changePage( "#menu", { transition: "slide"} ); 

            } else {
                alert('Invalid login. Please try again!'); // In case result is false throw an error
            }
            // This callback function will trigger on successful action
        },
        error: function (request,error) {
            // This callback function will trigger on unsuccessful action                
            alert('Connection error, please try again');
        }
    });
}

}

// We will use this object to store username and password before we serialize it and send to     server. This part can be done in numerous ways but I like this approach because it is simple
var userObject = {
username : "",
password : ""
}

------------用户验证.php -------------------

<?php
$jsonObject = json_decode($_REQUEST['outputJSON']); // Decode JSON object into readable PHP object
$username = $jsonObject->{'username'}; // Get username from object
$password = $jsonObject->{'password'}; // Get password from object
$connection = null;

$connection = new mysqli('127.0.0.1', 'xxxx', 'xxxx', 'xxxx'); 

$query = "SELECT * FROM clients WHERE username = '".$username."' and password = '".$password."'";
$result = mysqli_query($connection,$query);
$num = mysqli_affected_rows($connection);
if($num != 0) {
    echo "true";
} else {
    echo "false";        
}
?>

数据库(结构和关系)

客户ID、名称、用户名、密码、项目 ID、状态creation_date

项目ID, 项目, 描述, 技术, 状态, creation_date

错误ID 名称项目ID、类型、环境、描述、状态creation_date

projectid.clients = id.projects

id.projects = projectid.bugs

目标:将用户名存储在全局变量中,以便在另一个页面中恢复

最后,

我解决了创建一个名为 sessions 的新架构的此问题,当用户将其登录到应用程序时,它将存储在该架构中。在此之后,如果用户想要获取创建的错误列表,将调用一个新的sql句子来加入该搜索中的"会话"