2013-04-06 61 views
0

我有一个page 在这个页面上有两个选择年份和月份的表单。我想创建这样的东西如何创建一个提交参数的表单的方法

getTable($year, $month) 
{ 
} 

执行此方法后,它获得访问特定的表。如果我会在方法中选择2013和kwiecien,那么我会得到指定页面的表格。 我不知道如何使用代码发送数据来形成,我使用了什么?我使用Symfony2的

编辑: SOLUTION

$urltopost = "http://nbp.pl/transfer.aspx?c= 
    /ascx/listaabch.ascx&Typ=a&p=rok;mies&navid=archa"; 
      $datatopost = array (
      "mies" => "05", 
      "rok" => "12"     
      ); 

      $ch = curl_init ($urltopost); 
      curl_setopt ($ch, CURLOPT_POST, true); 
      curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost); 
      curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true); 
      $returndata = curl_exec ($ch); 
      curl_close($ch); 
      // var_dump($returndata); 
      print_r($returndata); 

它解决我的问题,

+0

php或aspx?,您的网页使用aspx而不是php ...如果php,那么生病给您创建一个示例 – daison12006013 2013-04-06 13:36:44

+0

php it将greate – konadrian 2013-04-06 13:41:16

回答

0

让我假设你的网站是基于PHP语言..

让我们说你的网站域名是“www.example.com”,我们需要通过GET过程“/home.php?year=2013”​​或“/home.php?year=2013 & month = 12”

让初始化home.php等于和月= 12是十二月

里面你的PHP代码:

<?php 
    function getTable($year,$month) 
    { 
     //Initializing global var 
     $year = 0; 
     $month = 0; 
     $result = ""; 
     //check if GET process "year" is set, and must not empty 
     if(isset($year) && $year != "") 
     { 
      //anti sql injection, and passing $_GET process to variables 
      $year = mysql_real_escape_string($year); 
      $result = mysql_query("SELECT * FROM data WHERE year=$year & month=$month") or die(mysql_error()); 

      //check if GET process "month" is set as well, and must not empty 
      if(isset($month) && $month != "") 
      { 
       //anti sql injection, and passing $_GET process to variables 
       $month = mysql_real_escape_string($month); 
       $result = mysql_query("SELECT * FROM data WHERE year=$year") or die(mysql_error()); 
      } 
     } 

     //check if $result doesnt have an error,security purposes 
     if($result) { 
      //loop the datas 
      while($row = mysql_fetch_array($result)) 
      { 
       if($month == 0) { 
        echo $row['year']; 
       }else { 
        echo $row['year']." ".$row['month']; 
       } 
      } 
     } 
    } 

    getTable($_GET['year'], $_GET['month']); 
?> 

这只是一个例子,这取决于你如何使用它... Selection语句仅仅是例子,需要改变...没有任何你需要的例子,你必须改变getTable函数在您需要之前...

相关问题