Cakephp从jquery null中选择 [英] Cakephp select from where jquery null
本文介绍了Cakephp从jquery null中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下是我的代码:
<div class="dropdown-menu" aria-labelledby="navbarDropdown">
<a class="dropdown-item" id="animal" value="1">Animal1</a>
<a class="dropdown-item" id="animal" value="2">Animal2</a>
<a class="dropdown-item" id="animal" value="3">Animal3</a>
</div>
我点击一下jQuery:
I have an jQuery one click:
$(document).ready(function() {
$("a#animal.dropdown-item").click(function() {
var animalvalue = $(this).attr("value");
$.ajax({
type: 'POST',
url: "/mycontroller/",
data: {animalvalue:animalvalue},
cache: false,
success: function(data) {
alert(data);
//$("#show").html(data);// here is the part of the problem
}
});
})
});
现在我有了我的控制器 - 这里我应该得到价值:
Now I have my controller - here I "should" get the value:
$jqueryanimalvalue = $this->request->getdata('animalvalue');
所以让我们看一下SQL语句:
So let's see the SQL statement:
$posts = $this->Posts->find()
->select()
->join([
'a' => [
'table' => 'animals',
'type' => 'INNER',
'conditions' =>'a.id = Posts.animal_id'
],
'u' => [
'table' => 'users',
'type' => 'INNER',
'conditions' =>'u.id = a.user_id'
]
])
->where(['u.id' => '2',
'a.id'=> $jqueryanimalvalue //here is null
]);
SELECT * FROM
posts Posts
INNER JOIN animals a ON a.id = Posts.animal_id
INNER JOIN users u ON u.id = a.user_id
WHERE
(
u.id = '2'
AND a.id = NULL //thats what i mean
)
这就是我的问题。点击后,他必须把动物的价值转向我,我可以选择。并且只有当我使用:
So that is my problem. After click he must to turn me the value of animal soo that i can make an select from. And only if I use :
$("#show").html(data);
它从SQL语句返回名称。为什么?我需要这个动物的值也可以用于控制器中的实习生
it returns the name from the SQL statement. Why? I need this value of animal to use it also for intern in controller
INSERT INTO WHERE animalid = $jqueryanimalvalue
推荐答案
您的SQL查询错误:
更改此:
$posts = $this->Posts->find()
->select()
->join([
'a' => [
'table' => 'animals',
'type' => 'INNER',
'conditions' =>'a.id = Posts.animal_id'
],
'u' => [
'table' => 'users',
'type' => 'INNER',
'conditions' =>'u.id = a.user_id'
]
])
->where(['u.id' => '2',
'a.id'=> $jqueryanimalvalue //here is null
]);
收件人:
$posts = $this->Posts->find()
->select()
->join([
'a' => [
'table' => 'animals',
'type' => 'INNER',
'conditions' => [
'a.id = Posts.animal_id',
'a.id IS ' . $jqueryanimalvalue // if it is null
]
],
'u' => [
'table' => 'users',
'type' => 'INNER',
'conditions' => [
'u.id = a.user_id',
'u.id' => '2'
]
]
]);
这篇关于Cakephp从jquery null中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文