PHP - Show All Records Before Current Month For This Year
Similar TutorialsHi, I'm wanting to find rows whose date is within the next week of the current month of the current year. The format of the date is, for example: 2010-10-28 Any ideas guys? Thanks lots! How to acheive it friends? i want my current codes to show results accouding to current month followed by year, the precious month goes to the page two.
would really appreciate if someone could help me acheive it
$tableName="records"; Edited by lovephp, 02 December 2014 - 11:50 AM. Hello this code is supposed to sort by year and month, but it doesn't. It sort by year and months are random. Any suggestions? Many thanks, $sortdata =[]; $namecolumn = array_column($data, '0'); foreach($data as $datecolumn){ $dateexplode = explode('/', $datecolumn[3]); $sortdata[] = (isset($dateexplode[1])) ? $dateexplode[1] : ((isset($dateexplode[0])) ? $dateexplode[0] : ''); } array_multisort($namecolumn, (($sorttype=='DESC') ? SORT_DESC : SORT_ASC), $sortdata, (($sorttype=='DESC') ? SORT_DESC : SORT_ASC), $data); Edited May 13 by Barand code tags added Thanks to aleX_hill and RussellReal for the help so far. I'm trying to utilise the code before to find the next month. However, it needs to be used with the current year. So I altered the below <?php $nextMonth = date("m") + 1; $daysInNextMonth = date("t",mktime(0,0,0,$nextMonth)); echo $daysInNextMonth;?> to #NEXT MONTH $nextMonth = date("m") + 1; echo $nextMonth; $daysInNextMonth = date("t",mktime(0,0,0,$nextMonth)); echo $daysInNextMonth ; $year = date("o"); echo $year; I can then pass it into my url query like so: <a href="<?php echo $url_path; ?>after=<?php echo $year; ?>-<?php echo $nextMonth; ?>-01&before=<?php echo $year; ?>-<?php echo $nextMonth; ?>-<?php echo $daysInNextMonth; ?>">Next Month</a> Brilliant I thought, until it comes to December 2010, the next month needs to be January 2011. Now I'm bamboozled. How do I get around this one? Many thanks, your help is always appreciated! right now i have my date system to say "X amount of seconds ago, X hours ago, X days ago, X years ago, How could i turn mktime() (1290874161) into a mm/dd/yyyy format? so it would say like, "Nov 27, 2010 at Hour:Minute" (whatever the hour/minute is) Hello, not sure if lack of sleep or just staring at code too long. This is what I have: Code: [Select] while($rowy = mysql_fetch_array( $resulty )) { mpdate = YYYY-MM-DD $date = $rowy['mpdate']; $year = explode('-', $date); $month = date("F", mktime(0, 0, 0, $year[1])); ?> <?php echo $year[0]; ?> <br> <?php echo $month; ?> <br> <?php echo $rowy['mptitle']; } ?> I figure if I use: if ($year[0] == date('Y"){ echo month and entry stuff } but I keep getting errors. What I am trying to do is sort everything out into year month and day ie: 2012 March Entry 1 Entry 2 February Entry 1 Entry 2 Entry 3 etc... This is what I am getting 2012 March Entry 1 2012 March Entry 2 2012 February Entry 1 etc... Is there a way to fix this? Hi Guys, Been a while since I've been on here, but I'm currently bashing my head against a wall trying to figure this one out. Basically I have a calendar that outputs Monday through Sunday, and the user clicks on a date and outputs it to the URL.... ie. ?day=$day&month=$month&year=$year. Now the next part I need to find out what day (0-6) say the 25th Feb 2011 will be wday 5... now how can I do this in code? And before anyone says why not output it to url, I cannot as the first week and last weeks use different code Cheers James Hi, I've got a date picker on a form which puts data into a database in the YYYY-MM-DD format. Just wondering how I could also put the name of the month (extracted from that) as well as just the year into separate columns. Ie: To use the field race_date from the form to also fill the 'race_month' and 'race_year' columns in the database. This code obviously only fills the 'race_date' column so far: Code: [Select] global $_POST; $race_date = $_POST["race_date"] ; .... $query = "INSERT INTO 10k_races (race_date, race_month, race_year)" . "VALUES ( '$race_date', '$race_month', '$race_year')"; Hi,
I want to display my data in this format
format.JPG 54.52KB
0 downloads
Expense data i am getting like this
<td><?php $in = "SELECT sales_invoice.invoice_id as INID, DATE_FORMAT(sales_invoice.date_invoiced,'%M') AS month, sales_invoice_line_items.invoice_id, SUM(sales_invoice_line_items.sub_total) AS Total, SUM(sales_invoice_line_items.tax_amount) AS total_tax FROM sales_invoice INNER JOIN sales_invoice_line_items ON sales_invoice.invoice_id=sales_invoice_line_items.invoice_id GROUP BY sales_invoice.invoice_id, DATE_FORMAT(sales_invoice.date_invoiced, '%Y-%m')"; $in1 = mysql_query($in) or die (mysql_error()); $total=0; $tax =0; while($income = mysql_fetch_array($in1)) { $total +=$income['Total']; $tax +=$income['total_tax']; echo $total - $tax; } ?> </td>And Profit i am getting like this <td><?php $in = "SELECT purchase_invoice.invoice_id as INID, DATE_FORMAT(purchase_invoice.date_invoiced,'%M') AS month, purchase_invoice_line_items.invoice_id, SUM(purchase_invoice_line_items.sub_total) AS Total, SUM(purchase_invoice_line_items.tax_amount) AS total_tax FROM purchase_invoice INNER JOIN purchase_invoice_line_items ON purchase_invoice.invoice_id=purchase_invoice_line_items.invoice_id GROUP BY purchase_invoice.invoice_id, DATE_FORMAT(purchase_invoice.date_invoiced, '%Y-%m')"; $in1 = mysql_query($in) or die (mysql_error()); $total=0; $tax =0; while($income = mysql_fetch_array($in1)) { $total +=$income['Total']; $tax +=$income['total_tax']; echo $total - $tax; } ?> </td>I dont know how to display data like this. Do i need to change the the table structure in my database? Please suggest 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! I have a file upload script that will eventually process a ton of files. I would like to upload them into sub-directories according to what year, month, and day they are uploaded.
A typical tree should look like this:
attachments/
--/2014
-----/January
--------/01
--------/02
--------/03 , etc.
-----/February
--------/01
--------/04
--------/09
--------/18
--------/20, etc
-----/March, etc
--/2015, etc.
So a file called image.jpg uploaded on 10/31/2014 would have a URL of attachments/2014/October/31/image.jpg. I understand that every time a file is uploaded, the script would have to detect through FTP whether or not folders for the year, month, and day exist, and if they don't create them. My problem is that I have no idea what the logic of this script would be. What order should I do things in? Is there a way to use maybe foreach to detect/create the folders? Any input would be appreciated.
Hi, I am having set of records, id name dob 1 philip 1278226800 2 winsent 1278216800 3 Benn 1272226800 now i want to fetch the records based on the month and listing out, can anyone help me to write for the above concept. Thanks, This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=332417.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=356136.0 hey guys, im trying to create a local event website displaying a calendar for each month showing local events. now i haven't got around to actually setting up the database yet so im sure i will be back with more questions about that soon, however im just trying to get the site frame work and im using a lot of includes as the site is subject to a lot of change etc. \ now basically i have a page called 'whatson.php' which im using this code to switch the include depending on the link clicked Code: [Select] <?php switch($_GET['changePage']) { default: case 'default': include('test1.php'); break; case 'january': include('january.php'); break; case 'february': include('february.php'); break; case 'march': include('march.php'); break; case 'april': include('april.php'); break; case 'may': include('may.php'); break; case 'june': include('june.php'); break; case 'july': include('july.php'); break; case 'august': include('august.php'); break; case 'september': include('september.php'); break; case 'october': include('october.php'); break; case 'novemeber': include('novemeber.php'); break; case 'december': include('december.php'); break; } ?> now what i want is the default page at the to to display the current month, so i was wondering if there is anyway somebody could help me out with a code that gets the current month from the server or somewhere and inserts it into the default month part at the top of that code... any help would be amazing I am trying to create a loop that will work through the dates of the current month; I have the following piece of code for the loop: Code: [Select] $monthFloor = DateTime::createFromFormat('j H:i:s', '1 0:0:0'); $monthCeiling = DateTime::createFromFormat('j H:i:s', $monthFloor->format('t').' 0:0:0'); for ( $monthDate = DateTime::createFromFormat('Y-m-d H:i:s', $monthFloor->format('Y-m-d H:i:s')); $monthDate->format('d') <= $monthCeiling->format('d'); $monthDate->modify('+ 1 day') ) { echo $monthDate->format('Y-m-d H:i:s')."<br />"; } But when I run this, it loops through the dates of the current month twice!? why is it doing this? and how can I rectify the loop so it only goes through the month once? Hello all,
Am trying to calculate some data and display the result of the current month in a chart form. i just don't know how to get the current month. this is not working..
<?php include('mysql_connect.php'); $date = 'MONTH(CURRENT_DATE())'; $status = 'paid'; //mysql_select_db("hyprops", $con); $query = mysql_query("SELECT sum(amount) 'amount', department FROM requisition WHERE status = '$status' AND date='$date' "); $category = array(); $category['name'] = 'department'; //$series1 = array(); //$series1['name'] = 'actual'; $series2 = array(); $series2['name'] = 'amount'; //$series3 = array(); //$series3['name'] = 'Highcharts'; while($r = mysql_fetch_array($query)) { $category['data'][] = $r['department']; // $series1['data'][] = $r['actual']; $series2['data'][] = $r['amount']; // $series3['data'][] = $r['highcharts']; } $result = array(); array_push($result,$category); //array_push($result,$series1); array_push($result,$series2); //array_push($result,$series3); print json_encode($result, JSON_NUMERIC_CHECK); mysql_close($con); ?>Please how can i solve this issue? Thanks in advance Hello. I'm new to pHp and I would like to know how to get my $date_posted to read as March 12, 2012, instead of 2012-12-03. Here is the code: Code: [Select] <?php $sql = " SELECT id, title, date_posted, summary FROM blog_posts ORDER BY date_posted ASC LIMIT 10 "; $result = mysql_query($sql); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $title = $row['title']; $date_posted = $row['date_posted']; $summary = $row['summary']; echo "<h3>$title</h3>\n"; echo "<p>$date_posted</p>\n"; echo "<p>$summary</p>\n"; echo "<p><a href=\"post.php?id=$id\" title=\"Read More\">Read More...</a></p>\n"; } ?> I have tried the date() function but it always updates with the current time & date so I'm a little confused on how I get this to work.
I'm trying to parse multiple rss feeds and only show and save items from the last month, but i can't get it to work. I've tried this: $pubdate = date("Y-m-d", strtotime($item->pubDate)); if (date($pubdate, strtotime(" -1 month")))
Hi all, I am trying to use the Mysql COUNT function to count the number of records in a database where the manufacturer is the same and then generate a list of all manufacturers along with a number of associated records next to their name. I have got the script below to show the manufacturer in a fetch array but I can not get the number next to the manufacturer to work. A push in the right direction would be appreciated thanks. <?php include("cxn.php"); $query = "SELECT manufacturer FROM sales"; $result = mysqli_query($cxn,$query) or die(mysqli_error()); ?> <select name="manufacturer" id="manufacturer"> <option value="" selected="selected">Select a Manufacturer..</option>"; <?php while($row = mysqli_fetch_array($result)){ $query1 = "SELECT manufacturer COUNT(*) FROM sales WHERE manufacturer='$row[manufacturer]'"; // TRYING TO COUNT THE ROWS HERE $result1 = mysqli_query($cxn,$query1) or die (mysqli_error()); while($row1 = mysqli_fetch_array($result1)){ echo "<option value=\"202\">".$row['manufacturer'] ."[". $row1['COUNT(manufacturer)']."]</option>"; // SHOW NUMBER HERE } } ?> |