0

ページがあります このページには、年と月を 2 つ選択するフォームがあります。そんなものを作りたい

getTable($year, $month)
{
}

このメソッドを実行すると、特定のテーブルにアクセスできます。メソッドで 2013 と kwiecien を選択すると、表のあるページを指定できます。コードを使用してフォームにデータを送信する方法がわかりません。何を使用していますか? 私はSymfony2を使用しています

編集:ソリューション

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

それは私の問題を解決しました、

4

1 に答える 1

0

あなたのウェブサイトがPHP言語に基づいていると仮定しましょう..

Web ドメインが「www.example.com」で、GET プロセス「/home.php?year=2013」または「/home.php?year=2013&month=12」を使用して渡す必要があるとします。

2013 年で、月 = 12が 12 月のhome.phpを初期化します。

あなたの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関数を変更する必要があります.. .

于 2013-04-06T14:06:45.753 に答える