我想问一下是否可以将三个值从PHP传递给jQuery?
你看我有这三个下降:一个用于本月,一个用于一年,一个用于用户。您可以选择查看所选月份和年份的用户数据。我现在所拥有的就是这个。
这是月,年和用户的下拉菜单:
$years = array(10=>'Select year','2011','2012','2013','2014','2015','2016','2017','2018','2019','2020','2021','2022','2023','2024','2025','2026','2027','2028','2029','2030');
$year_count= count($years);
$year = $year_count +9;
?>
<script type="text/javascript">
$(document).ready(function()
{
$("#months").change(function(event)
{
var m=$(this).val();
if(m!='00' || m!='NULL')
{
$("#memcount").load('crd_reports/month.php', {"m":m, "y": $("#years").val(), "user":$("#user").(val)});
$("#top10").load('crd_reports/top10_monthly.php', {"m":m, "y": $("#years").val()});
}
});
$("#years").change(function(event)
{
var y=$(this).val();
if(y!='10' || y!='NULL')
{
$("#memcount").load('crd_reports/month.php', {"y":y, "user":$("#user").val(), "m": $("#months").val()});
$("#top10").load('crd_reports/top10_monthly.php', {"y":y, "m": $("#months").val()});
}
});
$("#user").change(function(event)
{
var user=$(this).val();
if(user!='00' || user!='NULL')
{
$("#memcount").load('crd_reports/month.php', {"user":user, "m"m, "y:"y, "user": $("#user").val()});
}
});
});
</script>
<div align="left">
Month: <select id="months">
<option>Select month</option>
<option value='01'>Jan</option>
<option value='02'>Feb</option>
<option value='03'>Mar</option>
<option value='04'>Apr</option>
<option value='05'>May</option>
<option value='06'>June</option>
<option value='07'>July</option>
<option value='08'>Aug</option>
<option value='09'>Sept</option>
<option value='10'>Oct</option>
<option value='11'>Nov</option>
<option value='12'>Dec</option>
</select>
Year: <select id="years">
<?php
for($yr=10; $yr<=$year; $yr++)
{
echo "<option value='".$yr."'>".$years[$yr]."</option>";
}
echo "</select>";
echo "<br/><br/>";
echo "Select CRD User: <select id='user'>";
$sql = mysql_query("SELECT * FROM tbl_user WHERE admin_level LIKE 'CRD'");
while($fetch = mysql_fetch_array($sql))
{
echo "<option value='".$fetch['id']."'>".$fetch['username']."</option>";
}
?>
</select>
</div>
<br/>
<br/>
<div id ="memcount"><?php include('curr_month2.php')?></div> <!--display graph-->
<br/>
<br/>
<div id="top10"><?php include('curr_top10m.php')?></div> <!--display graph for top 10-->
这是php的代码,其中传递了月,年和用户的值:
<?php
if (isset($_POST['m']) && isset($_POST['y']) && isset($_POST['user']))
{
$m = $_POST['m'];
$y = $_POST['y'];
$user = $_POST['user'];
include '../../include/config.php';
$sql = "SELECT * FROM tbl_user WHERE admin_level LIKE 'CRD' ORDER BY id";
$result =mysql_query($sql);
?>
<div id='memcount' style='width: 680px; height: 350px; margin: 0 auto'></div>
<?php
$limit = 5;0
$c=0;
while($row = mysql_fetch_array($result))
{
$name[$c] = $row['first_name'];
$id[$c]= $row['id'];
$c++;
}
for($i=0; $i< $c; $i++)
{
$query2 = mysql_query("SELECT count(crdid) AS count_id, crdid, id, timestamp FROM crd_project
WHERE crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num!='NULL'");
while($fetch = mysql_fetch_array($query2))
{
$total[] = (int)$fetch['count_id'];
}
//week1
$week_1_id = mysql_query("SELECT crdid,count(crdid) AS week_1total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '1'
AND week_num!='NULL'");
while($week_1_num= mysql_fetch_array($week_1_id))
{
$week_1_tot[] = (int)$week_1_num['week_1total'];
}
//week2
$week_2_id = mysql_query("SELECT crdid,count(crdid) AS week_2total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '2'
AND week_num!='NULL'");
while($week_2_num= mysql_fetch_array($week_2_id))
{
$week_2_tot[] = (int)$week_2_num['week_2total'];
}
//week3
$week_3_id = mysql_query("SELECT crdid,count(crdid) AS week_3total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '3'
AND week_num!='NULL'");
while($week_3_num= mysql_fetch_array($week_3_id))
{
$week_3_tot[] = (int)$week_3_num['week_3total'];
}
//week4
$week_4_id = mysql_query("SELECT crdid,count(crdid) AS week_4total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '4'
AND week_num!='NULL'");
while($week_4_num= mysql_fetch_array($week_4_id))
{
$week_4_tot[] = (int)$week_4_num['week_4total'];
}
//week5
$week_5_id = mysql_query("SELECT crdid,count(crdid) AS week_5total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '5'
AND week_num!='NULL'");
while($week_5_num= mysql_fetch_array($week_5_id))
{
$week_5_tot[] = (int)$week_5_num['week_5total'];
}
//week6
$week_6_id = mysql_query("SELECT crdid,count(crdid) AS week_6total, week_num FROM crd_project
WHERE crdid!='NULL'
AND crdid='$user'
AND timestamp LIKE '%/$m/$y%'
AND week_num LIKE '6' AND week_num!='NULL'");
while($week_6_num= mysql_fetch_array($week_6_id))
{
$week_6_tot[] = (int)$week_6_num['week_6total'];
}
}
$fname = json_encode($name);
$total = json_encode($total);
$number = json_encode($c);
$week_1_total = json_encode($week_1_tot);
$week_2_total = json_encode($week_2_tot);
$week_3_total = json_encode($week_3_tot);
$week_4_total = json_encode($week_4_tot);
$week_5_total = json_encode($week_5_tot);
$week_6_total = json_encode($week_6_tot);
echo "<br/><br/><br/>";
}
?>
答案 0 :(得分:0)
是的,您可以将值从PHP传递给jquery。
You can place the value in hidden field and get it from that field in js, like <input type="hidden" id="someFld" value="value_from_php"> //get the value $("#someFld").val(); //or you can directly use the php value into js, like var yourJsVariable = '<?php echo $yourPHPValue; ?>';
希望有所帮助