PHP里面的JavaScript功能? [英] Php inside a javascript function?

查看:126
本文介绍了PHP里面的JavaScript功能?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用户收件箱中有一个功能,该功能使用户可以选中/取消选中他们希望收藏的邮件.

I have a feature on my users inbox that allows users to check/uncheck messages in their inbox that they want to make favourite.

我目前正在测试当用户选中该框(单击图像并使它从灰色变为彩色表示该框已选中)时会发生什么情况.

I'm currently testing what happens when a user checks the box (clicks on the image and causes it to go from greyed out to colour meaning the box is checked).

无论如何,当您选中此框时,从下面的代码中可以看到,此URL应该被加载: http://mysite.com/messages/favourite_checked

Anyway as you can see from the code below when the box ischecked this url is suppose to be loaded: http://mysite.com/messages/favourite_checked

用户选中该框的行的message_id假定要添加到url的末尾,然后加载我的控制器"messages"和方法"favourite_checked",然后传递一个变量,该变量从url,将其存储在变量中,然后将其发送给我的模型,并在mysql查询中使用.

The message_id of the row the user has checked the box on is suppose to be added onto the end of the url this then loads my controller "messages" and method "favourite_checked" which then passes a variable that grabs the message_id from the url, stores it in a variable then sends it the my model and it is used in a mysql query.

基本上,我更新消息表的收藏夹"列并将其设置为= 1,其中来自url的message_id与数据库中消息表中的"message_id"相匹配.所以,是的,在找到匹配项的地方,该行中的收藏夹"列更新为1.1 =收藏夹0 =不收藏.

Basically I update the favourites column of my messages table and set it to = 1 where the message_id from url matches the one in the messages table in my database. So yea, where the match is found the "favourite" column in that row is updated to 1. 1 = favourite 0 = not favourite.

任何我只是以为我会弄清楚发生了什么..

Any I just thought I would make it clear what was happening..

我的问题是,当我选中此框时,什么都不会发生,没有任何更新,因此,我觉得在尝试将id添加到javascript函数中的url时,我一定做错了.

My problem is nothing happens when I check the box, nothing is updated so I feel I must be doing something wrong where I try to add the id to the url in the javascript function.

我也尝试过$(post).然后什么也没发生.

I've tried $(post) also.. nothing happens then also.

也许有人可以发现它,因为我真的不知道问题出在哪里.

Maybe someone can spot it because I really don't know what the problem is.

<script type="text/javascript">

// favourite check box
    $('input.favourite:checkbox').simpleImageCheck({
  image: '<?php echo base_url()?>images/messages/check.png',
  imageChecked: '<?php echo base_url()?>images/messages/unchecked.png',
  afterCheck: function(isChecked) {
    if (isChecked) {



  //query to db from php to update favourite number to 1
  $.get('http://mysite.com/messages/favourite_checked'+'<?php foreach ($query as $row):  ?><?php $row['id']; ?><?php endforeach; ?>');

    }
//    else (!isChecked)
//        {
//            //query to db from php to update favourite number to 0
//              $.get('http://mysite.com/messages/favourite_unchecked');
//        }
  }
});
</script>

推荐答案

我认为您的基本问题是关于PHP与JavaScript何时运行的混淆.

I think your basic problem is some confusion about when the PHP is running vs the javascript.

您在页面上放置的PHP在服务器端,它将首先加载,然后javascript将在客户端运行.

The PHP you put on the page is server side, it will load first, then the javascript will run client-side.

这部分在这里:

$.get('http://mysite.com/messages/favourite_checked'+'<?php foreach ($query as $row):  ?><?php $row['id']; ?><?php endforeach; ?>');

似乎您希望根据所检查的内容动态显示该内容,但我看不到该网址将如何具体显示您要查找的内容.

Seems like you are wanting this to be dynamic based on what you checked, but I don't see how that url is going to show specifically what you are looking for.

这篇关于PHP里面的JavaScript功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆