我正在使用jQuery的fullCalendar插件,我遇到传递变量的问题。
基本上,我想要的是创建一个搜索并将搜索输入传递给资源选项的url。
我有一个搜索代码,它看起来像这样
<form action="employees.php" method="POST">
<input type="text" name="name" size="25" maxlength="230"
style="margin-left:5px;" value="" />
<br />
<p style="padding-top:10px; margin-left:5px;">
<input type="submit" value="Submit" class="button" />
</p>
</form>
带有Calendar脚本的employees.php如下所示:
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'today prev,next',
center: 'title',
right: ''
},
defaultView: 'resourceWeek',
refetchResources: true,
selectHelper: true,
numberOfWeeks: 1,
weekends: false,
firstDay: 1,
editable: false,
selectable: false,
refetchResources: true,
selectHelper: true,
resources: 'resource_employee.php',
// more code
?>
我的resource_employee.php页面如下所示
<?php
// some connection code
$name = mysql_real_escape_string($_POST[name]);
//$name = 'Goo';
//$result = mysql_query("SELECT CONCAT(first_name, ' ', last_name) AS name, employeeID FROM ecc_employee WHERE first_name != '' ");
$result = mysql_query("SELECT CONCAT(first_name, ' ', last_name) AS name, employeeID FROM ecc_employee WHERE CONCAT(first_name, ' ', last_name) LIKE '%$name%' ");
$resources = array();
while ($row=mysql_fetch_array($result)){
$name = ($row['name']);
$id = $row['employeeID'];
$resources[] = array(
'name' => "$name",
'id' => "$id"
);
}
echo json_encode($resources);
?>
不幸的是,这不会返回任何内容,因为$ _POST [name]不会被拉入此页面,因为它位于脚本中。
如果我取消注释// $ name ='Goo';然后它会渲染,所以我知道它不是SQL,它正在获得$ _POST。
如何在查询中获取$ _POST [name]?
答案 0 :(得分:1)
所以我可以通过以下方式获得$ _GET ['employeename']:
<script type='text/javascript'>
$(document).ready(function() {
var date = new Date();
var d = date.getDate();
var m = date.getMonth();
var y = date.getFullYear();
var calendar = $('#calendar').fullCalendar({
header: {
left: 'today prev,next',
center: 'title',
right: ''
},
defaultView: 'resourceWeek',
refetchResources: true,
selectHelper: true,
numberOfWeeks: 1,
weekends: false,
firstDay: 1,
editable: false,
selectable: false,
refetchResources: true,
selectHelper: true,
resources: 'resource_employee.php?employeename=<?php echo $_GET['employeename']; ?>',
events: 'events.php',
很简单,不知道为什么在任何其他问题中没有回答这个问题。希望这能为那些可怜的家伙节省时间。
答案 1 :(得分:0)
它应为$_POST['name']
单引号