小编Mic*_*sby的帖子

Codeigniter query-> num_rows返回0不正确

我似乎无法得到以下查询运行并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)

php codeigniter

3
推荐指数
1
解决办法
2734
查看次数

在CodeIgniter中使用jQuery JSON

在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 codeigniter

2
推荐指数
1
解决办法
7705
查看次数

将PHP/MySQL数据拆分为3列

我需要在PHP中创建3个HTML列,其中包含从MySQL返回的数据.我想在所有3列之间平均分配数据......我将如何做到这一点?

html php

2
推荐指数
1
解决办法
4492
查看次数

扩展MySQL语句

在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)

php mysql codeigniter

1
推荐指数
1
解决办法
60
查看次数

jquery如何在执行ajax调用后获取click事件的索引

在下面的代码中$(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)

javascript jquery

1
推荐指数
1
解决办法
102
查看次数

在Codeigniter插入数组中使用类似NOW()的东西

因为NOW()是一个MySQL方法,我似乎无法让它在下面的数组中工作.什么是我可以在PHP中使用的函数,它将与NOW()方法做同样的事情.

$data = array('node1id' => $leader_id,
              'node2id' => $idgen,
              'friendsSince' => NOW(),
$this->db->insert('users', $data);
Run Code Online (Sandbox Code Playgroud)

php codeigniter

1
推荐指数
2
解决办法
1万
查看次数

识别MySQL while循环中的第3行

我正在做的是每输出3个MySQL数据库行,我将运行一个输出不同的自定义函数.我如何识别每第3排?

php mysql

0
推荐指数
1
解决办法
190
查看次数

将多个事件绑定到jQuery中的一个选择器

$("#action_button").click(function() {
Run Code Online (Sandbox Code Playgroud)

如何将onEnter事件与不同的选择器绑定到上面的相同代码?

javascript jquery

0
推荐指数
1
解决办法
1710
查看次数

PHP计算字符串中的字符

可能重复:
如何在php中获取字符串的确切长度?

PHP中计算字符串中字符数的最佳方法是什么.我做了网络搜索,似乎找不到任何东西.

php

0
推荐指数
1
解决办法
2万
查看次数

head.js抛出属性js未找到错误

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)

javascript

0
推荐指数
1
解决办法
1027
查看次数

Javascript没有正确地提取attr值

出于某种原因,每当我点击进入时,我都会看到一个未定义出现的警告框.我的脚本应该获取"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)

jquery

-1
推荐指数
1
解决办法
188
查看次数

标签 统计

php ×7

codeigniter ×4

javascript ×3

jquery ×3

mysql ×2

html ×1