dtddjq9637 2011-12-01 00:54
浏览 55

三个PHP值传递给jQuery

I would just like to ask if passing of three values from PHP to jQuery would be possible?

you see i have this three drop downs: one for the month, one for the year and one for the user. you can choose to view the data of the user on the chosen month and year. all i have right now is this.

This is the drop down for the month, year and user:

$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-->

This is the code for the php where the value of month, year and user were passed:

<?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/>";
}
?>
  • 写回答

1条回答 默认 最新

  • dongzhuo2010 2011-12-01 01:13
    关注

    Yes you can pass value from PHP to 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; ?>';
    

    Hope it helps

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分