PHP - Moved: Select Years And There Month Mysql
This topic has been moved to MySQL Help.
http://www.phpfreaks.com/forums/index.php?topic=318996.0 Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356136.0 i want to make a monthly report the user selects month from drop down and i must get the specified dates of that month from the DB I am using ajax to get the dates Hello. I have a mysql database with an 'entrytime' field which contains the unix timestamp the record was added. How do I create a mysql query to select all records for a given month/year? For example, if I wanted to create a query to display all records for October 2010 how do I go about it? I am at a loss and can't find my answer via google. Thanks in advance for any help! This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350716.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=348309.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321906.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310181.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=351005.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=347691.0 Hi i have this drop down list current the year is 2010 and downwards but i want to change the list to 2010 upwards u can notice on the 50-- so shows current year minus so current is 2010 to 61 how can i change 2010 to 2030 or sunfin?? echo '<select name="year_of_birth">',"\n"; $year = date("Y"); for ($i = $year;$i > $year-50;$i--) { if($i == $thisYear) { $s = ' selected'; } else { $s=''; } echo '<option value="' ,$i, '"',$s,'>' ,$i, '</option>',"\n"; } echo '</select>',"\n"; This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=355706.0 so im trying to setup a page for my bills that i pay monthly so me and my gf can access it remotely whenever we need to. we have a few loans that we are paying off in installment loans every month so i created a table like the picture below (which is actually in excel but it looks about the same). i know how to pull via select and sum everything that i need but what i'm actually going for is this: every month on those certain due dates i'd like for the monthly payment to be subtracted from the balance automatically..and it show the reflected balance. i'm not sure how to go about such a thing though as i've never worked with dates and times. my logic is that i have to setup a beginning time stamp for it to work off of..and then every 30 days from that time stamp..subtract the payment. then again, there's not always 30 days in a month and it'd get off track. any ideas? Hi guys, Im having problem on how to achieved this one.. I would like to get the all event of this month (April ) Starting todays date.. Code: (php) [Select] $now = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+8, gmdate("Y"))); $week = gmdate("Y-m-d", mktime(gmdate("H")+8, gmdate("i"), gmdate("s"), gmdate("m"), gmdate("d")+30, gmdate("Y"))); if ($result = mysql_query("SELECT * FROM fiesta WHERE sta_date BETWEEN '$now' AND '$week' ORDER BY sta_date LIMIT 10")){ if (mysql_num_rows($result)) { $return = ''; while ($row = mysql_fetch_array( $result )) { $date = date("D",strtotime($row["sta_date"])); $return .= "<a href='sta.php' style='font-size:11px;' title='" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "'>" . $row['fiesta_brgy'] . " " . $row['fiesta_town'] . "</a> ($date), "; } echo rtrim($return, ', '); } } The result of this query will include the events on May.. How can i display only the event on this month(April)? starting todays date. Thank you Hi friends, I'm looking to try and echo the profits from a MySQL "totals" table for each month of the year... the table bascically consists of a "totals" column which contains the total amount spent on each order, a "suppliertotals" column which contains the total amount that it costs us to buy the goods for that order and an "orderdate" column which stores the order date as "d/m/y" (so 01/01/01). To work out the total margin from the complete table, I calculate the sum of totals minus the sum of suppliertotals. This is our margin. I'm currently doing the calculation with MySQL's sum() function, and using PHP explode to get the date, but I'm obviously doing something wrong since PHP is returning the same month several times with different amounts... Let me show you the code I have; I presume I need to use some kind of foreach statement, but I'm not sure where or how... hoping you can help! if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("onetelec_wsshop", $con); $result=mysql_query("SELECT orderdate FROM totals", $con); while($row = mysql_fetch_array($result)) { $ordmonth = explode("/", $row['orderdate']); $ordmonth = $ordmonth[1]; switch ($ordmonth) { case "01": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for January<br /><br />"; break; case "02": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for February<br /><br />"; break; case "03": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for March<br /><br />"; break; case "04": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for April<br /><br />"; break; case "05": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for May<br /><br />"; break; case "06": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for June<br /><br />"; break; case "07": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for July<br /><br />"; break; case "08": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for August<br /><br />"; break; case "09": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin = $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for September<br /><br />"; break; case "10": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin += $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for October<br /><br />"; break; case "11": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin += $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for November<br /><br />"; break; case "12": $stresult=mysql_query("SELECT sum(total), sum(stotal) FROM totals WHERE ordate LIKE '%/$ordmonth/%'", $con); while($strow = mysql_fetch_array($stresult)) { $margin += $strow['sum(total)'] - $strow['sum(stotal)']; } echo $margin." for December<br /><br />"; break; } } Hi, I have a table that contains posts and each post has a datetime field. Im trying to work out how I can show entries from today, this week and this month so I can have a link that shows all posts from today or this month etc. Any one know how I can do this ? My current piece of code that pulls the data from the db looks like this : Code: [Select] $texts= mysql_query("SELECT * FROM submittedtexts Order by id DESC LIMIT " . (($page - 1) * 6) . ", 6"); I want to add a bit that acts like : WHERE date = today Hope that makes sense, Im a bit of a newbie Thanks in advance, Scott Hi.. I need help in getting the 3 Months Name from my table field FromMonth and ToMonth. Here is the scenario. First, I select FromMonth and ToMonth. Ex. FromMonth = 5 ToMonth = 7 So it means FromMonth is May ToMonth is July. Now I save the MonthNumber to my database: table- so_month FromMonth = 5 ToMonth = 7 Now I need to get the between Months Name from FromMonth to ToMonth which are (May, June, July). How does it possible? Thank you so much. Trying to get the below to generate the month in word form from a numeric entry in a database. Code: [Select] elseif($_GET['rma']=="calander"){ $sql101010="SELECT DISTINCT rma_year_issued FROM $tbl_name4 ORDER BY rma_year_issued"; $result101010=mysql_query($sql101010); while($row101010=mysql_fetch_array($result101010)){ extract($row101010); $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'">'.$rma_year_issued.'</a> <br />'; } if(isset($_GET['year'])){ $logout.=' | <a href="./acp_admincp.php?rma=calander">Back to RMA Calander</a>'; $rma_year_issued=$_GET['year']; $sql111010="SELECT DISTINCT rma_month_issued FROM $tbl_name4 WHERE rma_year_issued='$rma_year_issued' ORDER BY rma_month_issued"; $result111010=mysql_query($sql111010); while($row111010=mysql_fetch_array($result111010)){ extract($row111010); $months = array('Janurary', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); for($i=0; $i <=11; $i++){ if($rma_month_issued=$i){ $rma_month_issued2=$months[$i]; } } $content=""; $content.='<a href="./acp_admincp.php?rma=calander&year='.$rma_year_issued.'&month='.$rma_month_issued.'">'.$rma_month_issued2.'</a> <br />'; } } } Basically in the data base I may have 2,5,7 under the year 2011. I want to get the numeric months into words for use in the text of the link. The above is returning December even though the entry in the database is 5. So I am creating a list of events. There will be a drop down menu to change between months. I only want the months to be listed if an event during that month exists. So if I have events listed for September and November, list only September and November, skipping October. Any idea on how to approach this or if there are any functions for such a thing? This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=320341.0 Hi Guys, In a form within PHP coding i can get the the next 10 years with the following code: Code: (php) [Select] <?php $date_future = date("Y", strtotime('+10 year')); $date_year = date("Y"); for($i=$date_year;$i<$date_future;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I have tried to mess about with the same code and try and get it to work for the last 10 years without any luck. He's what i did: Code: (php) [Select] <?php $date_past = date("Y", strtotime('-10 year')); $date_year = date("Y"); for($i=$date_year;$i>$date_past;$i++){ if($date_year == $i){ echo "<option value=\"$i\" selected=\"selected\">$i</option> \n"; } else { echo "<option value=\"$i\">$i</option> \n"; } } ?> I would appreciate any help with this. |