我似乎无法得到以下查询运行并num_rows正确返回.无论发生什么,即使我期望它返回,也$query->num_rows > 0总会返回.有任何想法吗?falsetrue
$post_id = $this->input->post('post_id');
$poster_id = $this->input->post('poster_id');
$my_id = $this->session->userdata('id');
$query = $this->db->query("SELECT * FROM default_post_likes
WHERE liker_id = '$my_id'
AND post_id = '$post_id'");
if ($query->num_rows > 0) {
echo json_encode(array('error' => 'e1'));
} else {
$data = array(
'poster_id' => $poster_id,
'post_id' => $post_id,
'liker_id' => $my_id
);
$this->db->insert('default_post_likes', $data);
echo json_encode(array('success' => true));
}
Run Code Online (Sandbox Code Playgroud) 在CI中,我使用logsig()方法设置了一个控制器.然后在我的index()方法中,我正在调用一个名为startpage的视图.在我看来,我正在使用JSON在我的视图和我的控制器之间进行异步调用.我该如何编写电话代码.以下是我的代码:
位指示:
function logsig() {
$this->load->view('startpage', $sync);
header('Content-type:application/json'); .............
Run Code Online (Sandbox Code Playgroud)
视图:
<script type="text/javascript" language="javascript">
$(document).ready(function() {
// blink script
$('#notice').blink();
$("#action_button").click(function() {
var username = $("#username").val();
var password = $("#password").val();
var dataString = '&username=' + username + '&password=' + password;
if(username=='' || password=='') {
$('#success').fadeOut(400).hide();
$('#error').fadeOut(400).show();
} else {
$.ajax({
type: "POST",
dataType: "JSON",
url: "processing/logsig.php",
data: dataString,
json: {session_state: true},
success: function(data){
if(data.session_state == true) { // true means user is logged in.
$("#main1").hide();
$('#main1').load('<?=$sync?>').fadeIn();
} else if(data.session_state == false) …Run Code Online (Sandbox Code Playgroud) 我需要在PHP中创建3个HTML列,其中包含从MySQL返回的数据.我想在所有3列之间平均分配数据......我将如何做到这一点?
在CodeIgniter或PHP中是否可以扩展MySQL语句.例如.如果我有$query1.我可以$query1在另一个$this->db->query()实例中添加:
$query1 = this->db->query("SELECT * FROM users WHERE a = b");
$query1(or 2) = $this->db->query("AND b = c");
Run Code Online (Sandbox Code Playgroud) 在下面的代码中$(this).parents('#friendRequest').remove();,我将如何在我的ajax成功回调函数中使用,并用于$(this)获取第一行中click事件的选择器?
jQuery(".notyAcceptFriendRequest").on('click', function() {
notyId = jQuery(this).attr("notyIdOne"); // pull in the id of the current selected notification
userProfilesUserId = $('#requestAlert').attr('userProfilesUserId'); // pull in the id of the current selected user profile id
if (notyId == userProfilesUserId) { // if notification id is the same as the user profiles id, do the following
$("#requestAlert").replaceWith('<span class="font1">You two are now friends</span>'); // the user profile friend requester will be replaced with the text
$(this).parents('#friendRequest').remove(); // find the '#friendRequest' id …Run Code Online (Sandbox Code Playgroud) 因为NOW()是一个MySQL方法,我似乎无法让它在下面的数组中工作.什么是我可以在PHP中使用的函数,它将与NOW()方法做同样的事情.
$data = array('node1id' => $leader_id,
'node2id' => $idgen,
'friendsSince' => NOW(),
$this->db->insert('users', $data);
Run Code Online (Sandbox Code Playgroud) $("#action_button").click(function() {
Run Code Online (Sandbox Code Playgroud)
如何将onEnter事件与不同的选择器绑定到上面的相同代码?
可能重复:
如何在php中获取字符串的确切长度?
PHP中计算字符串中字符数的最佳方法是什么.我做了网络搜索,似乎找不到任何东西.
Chrome会引发以下错误:
未捕获的TypeError:对象函数(){d.ready.apply(null,arguments)}的属性'js'不是函数
虽然Firefox抛出了一个 TypeError: head.js is not a function
这是我的代码:
<!doctype html>
<html lang="eng" ng-app="app">
<head>
<meta charset="UTF-8">
<title>{{ page_title }}</title>
<script src="http://cdnjs.cloudflare.com/ajax/libs/headjs/0.99/head.core.min.js"></script>
</head>
<script>
head.js({ angularJS: "https://ajax.googleapis.com/ajax/libs/angularjs/1.0.7/angular.min.js"},
{ jQuery: "http://code.jquery.com/jquery-1.10.1.min.js" },
{ internalApp: "app/js/app.js"});
head.ready('jQuery', function() {
$(document).ready(function() {
console.log('jQuery loaded successfully');
});
});
</script>
<body>
<!-- add data here -->
</body>
</html>
Run Code Online (Sandbox Code Playgroud) 出于某种原因,每当我点击进入时,我都会看到一个未定义出现的警告框.我的脚本应该获取"rel"attr,然后将其输出到alertbox.关于为什么不发生这种情况的任何想法?
我的jQuery:
// process addComment()
jQuery(".textbox1").keydown(function(event) {
var keyCode = event.keyCode || event.which;
if (keyCode === 13) {
addComment(this);
}
});
function addComment(e) {
var id = jQuery(e).attr("rel");
alert(id);
}
Run Code Online (Sandbox Code Playgroud)
我的Html:
<input placeholder="Write a comment..." id="commentBox-<?php echo $row->idwallPosts; ?>" class="textbox1" style="width: 423px">
Run Code Online (Sandbox Code Playgroud)