Saturday 15 June 2013

Selecting month in HTML and executing a PHP query -


I am working on something with a database and with PHP to manage my finances. From my homepage I want to select one month and execute a query so that only records can be displayed in this month's database.

Now I have this:

  if (isset ($ _gET ['january2013'])) // // Select the earnings {$ sql = 'SELECT Id, type, date, amount, statement, class from `transaction ', where type =" income "and month (date) ='. $ Month selection 'order by `transaction`.` ID` DESC limit 0,50'; $ Result2 = $ pdo- & gt; Query ($ sql); } //error handling. Hold (PDOException $ e) {$ output3 = 'Error getting record:'. $ E & gt; GetMessage (); Include '/errors/output.html.php'; Go out(); } // Display Record Foreach ($ result2 as $ row) {$ inJan2013 [] = Array ('id' = & gt; $ row ['id'], 'type' = & gt; $ row ['type' $ Line ['date'], 'zodiac' = & gt; $ line ['zodiac'], 'description' = & gt; $ line ['description'], 'category' = & Gt; $ line ['category']); }   

Instead of making this code every month, how can I make it more universal? I want to use the $ monthselect variable, but I do not know where to start from

on your webpage,

  & lt; Form action = "where_you_handle_your_requests.php" method = "post" & gt; & Lt; Select name = "mo" & gt; & Lt; Option value = "Jan" & gt; January & lt; / Options & gt; & Lt; Option value = "February" & gt; February & lt; / Options & gt; & Lt; Option value = "march" & gt; March & lt; / Options & gt; & Lt; / Select & gt; & Lt; Select name = "yr" & gt; & Lt; Option value = "2010" & gt; 2010 & lt; / Options & gt; & Lt; Option value = "2011" & gt; 2011 & lt; / Options & gt; & Lt; / Select & gt; & Lt; / Form & gt;   

even further.

Next, on your PHP script,

  if (isset ($ _ POST ['yr']) & Amp; isset ($ _ POST ['mo'] )) {$ Monthselect = $ _ POST ['mo']. $ _ POST ['yr']; } Else {// has not passed for an input script}   

If the user has selected January 2013, then the month's selection is january2013

No comments:

Post a Comment