PHP - Php Grouping Data To Years
How can i group the data by year to build the graph
I need the data to be like so 2012 0 - total customers 0 - total customers 0 - total customers 0 - total customers 0 - total customers 9 - total customers 5 - total customers 3 - total customers 5 - total customers however i only have this data Code: [Select] total_customers month year 1 Aug 2011 9 Oct 2011 8 Nov 2011 4 Dec 2011 4 Jan 2012 so i need to make it show 0 for the months i dont have data for Code: [Select] <div id="dash_chart" class="portlet x9"> <div class="portlet-header"> <h4>Customer Growth</h4> <ul class="portlet-tab-nav"> <li class="portlet-tab-nav-active"><a href="#tab1" rel="tooltip" title="Customers">Customers </a></li> <li class=""><a href="#tab2" rel="tooltip" title="Sales over last 48 hours.">Sales </a></li> </ul> </div> <!-- .portlet-header --> <div class="portlet-content"> <div id="tab1" class="portlet-tab-content portlet-tab-content-active"> <?php echo '<table class="stats" title="area" width="100%" cellpadding="0" cellspacing="0"> <caption>Customer Base Growth</caption> <thead> <tr>'; $monthNames = Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); $i = 0; foreach ($monthNames as $month){ echo '<th>'.$month.'</th>'."\n"; } echo '</tr> </thead>'; $q = "SELECT count(cus_id) as total_customers, DATE_FORMAT(sign_date, '%b') as month, YEAR(sign_date) as year FROM customers GROUP BY YEAR(sign_date), MONTH(sign_date) ORDER BY sign_date ASC"; $r = @mysqli_query ($dbc, $q); $data = array(); if (mysqli_affected_rows($dbc) >= 1) { echo '<tbody> <tr> <th>2011</th>'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { } } echo '</tr>'; ?> <tr> <th>2012</th> <td>3</td> <td>4</td> <td>2</td> <td>0</td> <td>0</td> <td>0</td> <td>0</td> <td>3</td> <td>5</td> <td>3</td> <td>9</td> </tr> </tbody> </table> Similar Tutorialsgrouping - i need to add an option where i can select ALL of the branches -then my table will show all list of employees' leaves from all the branches.. -to make it easier to view all the leave details when i select ALL.. -instead of having to preview all the branches 1 by 1. -do i need to modify my view on my database or just modify my codes..what codes should i use. -Please tell me where and what do i need to change. Code: [Select] <h3><FORM name ="reportbutton" method="post" align="left" action="index.php?view=report"> <strong>Leave Application Listing </strong>| <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Back To Report"> </h3> </FORM> <br><br> <form name="leavebutton" method="post" action="index.php?view=report_leave"> <? $b=$_GET['b']; $m=$_GET['m']; $y=$_GET['y']; if ($b <> '' && $m <> '' && $y <> '') { $branch=$b; $leavemonth=$m; $leaveyear=$y; } else { $branch=$_POST['branch']; $leavemonth=$_POST['leavemonth']; $leaveyear=$_POST['leaveyear']; } $connection=mysql_connect("$server", "$username", "$password") or die("Could not establish connection"); mysql_select_db($database_name, $connection) or die ("Could not select database"); $query="SELECT * from tblworkgroup"; $result=mysql_query($query);?> Branch <select name="branch" > <? while($row=mysql_fetch_array($result)) { ?> <option value= "<?=$row['WorkGroupID']?>" <? if ($branch==$row['WorkGroupID']){ echo 'selected'; } ?> ><?=$row['WorkGroupName']?></option> <? } ?> </select> </td> </tr> <br><br><br> Month <select name="leavemonth" > <option value = "1" <? if ($leavemonth==1){ echo 'selected'; } ?>>January</option> <option value = "2" <? if ($leavemonth==2){ echo 'selected'; } ?>>February</option> <option value = "3" <? if ($leavemonth==3){ echo 'selected'; } ?>>March</option> <option value = "4" <? if ($leavemonth==4){ echo 'selected'; } ?>>April</option> <option value = "5" <? if ($leavemonth==5){ echo 'selected'; } ?>>May</option> <option value = "6" <? if ($leavemonth==6){ echo 'selected'; } ?>>June</option> <option value = "7" <? if ($leavemonth==7){ echo 'selected'; } ?>>July</option> <option value = "8" <? if ($leavemonth==8){ echo 'selected'; } ?>>August</option> <option value = "9" <? if ($leavemonth==9){ echo 'selected'; } ?>>September</option> <option value = "10" <? if ($leavemonth==10){ echo 'selected'; } ?>>October</option> <option value = "11" <? if ($leavemonth==11){ echo 'selected'; } ?>>November</option> <option value = "12" <? if ($leavemonth==12){ echo 'selected'; } ?>>December</option> </select> Year <select name="leaveyear" > <option value = "2010" <? if ($leaveyear==2010) { echo 'selected';} ?>>2010</option> <option value = "2011" <? if ($leaveyear==2011) { echo 'selected';} ?>>2011</option> <option value = "2012" <? if ($leaveyear==2012) { echo 'selected';} ?>>2012</option> <option value = "2013" <? if ($leaveyear==2013) { echo 'selected';} ?>>2013</option> <option value = "2014" <? if ($leaveyear==2014) { echo 'selected';} ?>>2014</option> <option value = "2015" <? if ($leaveyear==2015) { echo 'selected';} ?>>2015</option> <option value = "2016" <? if ($leaveyear==2016) { echo 'selected';} ?>>2016</option> <option value = "2017" <? if ($leaveyear==2017) { echo 'selected';} ?>>2017</option> </select> <input type='submit' name='submit' value='Preview' Class="button" onclick='return validate()'> </div> </form> <br /><br /> <div id="box" valign="top"> <h3> <strong>Leave Application Details</strong>  </h3> <br><br> <FORM name="printbutton" method="post" align="left" action="report_print.php" target="_blank"> <input type="hidden" name="leavemonth" value="<?php echo $leavemonth; ?>"> <input type="hidden" name="leaveyear" value="<?php echo $leaveyear; ?>"> <input type="hidden" name="branch" value="<?php echo $branch;?>"> <Input type = "Submit" Name = "Submit1" Class="button" VALUE = "Print Leave Details"> </form> <table width="80%" align="center" > <thead> <tr> <th width="700px" align="left">Name</a></th> <th width="500px" align="center"></a>Application</th> <th width="500px" align="center"></a>Date</th> <th width="500x" align="right"></a>Reason</th> </tr> </thead> <tbody> <? /*echo "branch:".$branch.'<br />'; echo "leavemonth:".$leavemonth.'<br />'; echo "leaveyear:".$leaveyear.'<br />';*/ //-------------------------------------------------- if ($leavemonth =='' || $leaveyear =='' || $branch == '') { // one value missing, so don't display } else { // start display data $rs = mysql_query( " call vwleavereport('$leavemonth', '$leaveyear', $branchid, 0);"); $query="SELECT *, MONTH(tblleaveapplication.DateFrom) as DFMonth, MONTH(tblleaveapplication.DateTo) as DTMonth, YEAR(tblleaveapplication.DateFrom) as DFYear FROM `tblleaveapplication` LEFT JOIN `tblemployee` ON tblleaveapplication.employeeid = tblemployee.id WHERE WorkGroupID = '".$branch."' AND ( (MONTH(tblleaveapplication.DateFrom)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") OR (MONTH(tblleaveapplication.DateTo)=".$leavemonth." AND YEAR(tblleaveapplication.DateFrom)=".$leaveyear.") ) "; $result = mysql_query($query); while($row=mysql_fetch_array($result)) { echo '<tr>'; echo '<td>'.$row['EmployeeName'].'</td>'; echo '<td>'.$row['DateFrom'].'</td>'; echo '<td>'.$row['DateTo'].'</td>'; echo '<td>'.$row['Purpose'].'</td>'; echo '</tr>'; } } ?> </table> This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=314247.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"; I can determine 3 years from today, but How do determineo 3 years from march 1st? So I want to echo out "3/1/2013"? Thanks! 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. I am searching the database for items that are plaques. There are different years of plaques. I find all the plaques sorted by year. My display puts them in rows of 4 max. What I want is to display them by year with a different year on a different line. Right now there are 4 (1963), 3 (1965), 1 (1978) all bunched together. 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978 What I want is: 1963, 1963, 1963, 1963, 1965, 1965, 1965, 1978, Any help would greatly be appreciated. <?php include 'config0.php'; $search=$_GET["search"]; // Connect to server and select database. mysql_connect($dbhost, $dbuser, $dbpass)or die("cannot connect"); mysql_select_db("$dbname")or die("cannot select DB"); $result = mysql_query("SELECT * FROM table1 WHERE plaques LIKE '%$search%' ORDER BY year") or die(mysql_error()); // store the record of the "" table into $row //$current = ''; // keeps getting the next row until there are no more to get if($result && mysql_num_rows($result) > 0) { $i = 0; $max_columns = 4; echo "<table align=center>"; echo "<br>"; while($row = mysql_fetch_array($result)) { // make the variables easy to deal with extract($row); // open row if counter is zero if($i == 0) echo "<tr>"; echo "<td align=center>"; ?> <div style="float: left;"> <div><img src="<?php echo $tn; ?>"></div> </div> <?php echo "</td>"; // increment counter - if counter = max columns, reset counter and close row if(++$i == $max_columns) { echo "</tr>"; $i=0; } // end if } // end while } // end if results // clean up table - makes your code valid! if($i > 0) { for($j=$i; $j<$max_columns;$j++) echo "<td> </td>"; echo '</tr>'; } mysql_close(); ?> </table> Ok so here is my code. Ignore the $_POST['dobm']. That is part of the whole script. All I want to know is how to set the list from 1998 to 1911 in descending order. I already tried making $i = 1998 and make $i - 1 til $i >= 1911. It seems to go in an infinite loop when I do that. Code: [Select] <?php for($i = 1911; $i <= 1998; $i++) { if ($_POST['dobm'] == $i) { echo '<option selected="selected" value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } else { echo '<option value="'.$i.'">'.date('Y', mktime(0,0,0,0,0,$i+1)).'</option>\n'; } } ?> Hi everyone, I'm writing a science fiction wordpress blog set 10 years into the future. I basically need all posts to display as if they are 10 years from now. Eg. posts needs to display as: February 7, 2021 instead of February 7, 2011 This will be for every post that I write. How can I automatically add 10 years to every post date? (And where would I put that code?) Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>` I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =) I hope someone out there can help. It would be very much appreciated. many thanks in advance Luke Hello All, I have a News database in which articles are entered in. Right now all the stories are being display in one big page with every story on it. What I would like to do is to create an "archive" in which it automatically organizes the stories by their date. For example. 2011 February January 2010 December November October September etc... etc... I have a datetime field for the database, and I know how to do this all manually, but I can't figure out how to make it automatically add a month each month. It would be too much maintanence to have to update this every month. I also don't know what this would be called, so I don't even know what to search for. I've tried blog and news, but doesn't seem to be what I want. Any help would be appreciated! if(!is_array($e)) { $fulldisp = 1; $e = array('title' => 'No Entries Yet', 'entry' => '<a href="../admin.php">Post an entry!</a>' ); } } // Add the $fulldisp flag to the end of the array array_push($e, $fulldisp); return $e; } can someone please tell me why I'm getting this notice ? Notice: Undefined variable: e in /var/www/blog/inc/functions.inc.php on line 40 I write with Object orientated programming style in all languages where possible. Languages i am experienced with: PHP4/PHP5 Mysql/Mysqli/PDO CSS/CSS3 Html/html5 Javascript (i prefer not to use libraries but i can use jquery just fine). C++ Console C# Silverlight C# windows phone 8.1 Graphic design: Photoshop cs6 fireworks cs6 (i prefer not to use fireworks though) Familiar operating systems: Linux Windows Extra info: I work with Apache and have experience maintaining the server. I like to work over SSH (secure shell). I program in Notepad or command prompt only!. I do not use frameworks or special software! Again i am looking for IMMEDIATE work. Thanks Sometimes i over think things and need to be told EXACTLY what it is you want VERY SLOWLY. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=318996.0 I want to set a never expire date, so I figured I would set the date 99 years into the future. No dice. After trial and error, it appears you can only make it 25 years into futu date("Y-m-d",strtotime("+25 years")); I wonder if it is the absolute date, or the number 25. If it is the maximum date (i.e. nothing after 2035) then I will have a problem with this code next year! I have this form:
I have started learning OOP, by following a few tutorials, My problem with most tutorial is they show you how, but don't tell you the what and the why. It's all good an well seeing what to do, but if you have no idea why it's being done, you don't learn much. I started a tutorial on Udemy but am not actually gaining a lot from it. I want to alter the code so that it will do it the way I want it to. I am not wanting you to write the code for me, if you do please explain it so that I can understand the logic, preferably show me where to make changes and point me at the php tutorial that can solve my problem. I have been trying to solve this for a couple of weeks now, I tried a few things but none worked.
The full followLinks function function followLinks($url) { global $alreadyCrawled; global $crawling; $host = parse_url($url)["host"]; $parser = new DomDocumentParser($url); $linkList = $parser->getLinks(); foreach($linkList as $link) { $href = $link->getAttribute("href"); if((substr($href, 0, 3) !== "../") AND (strpos($href, $host) === false)) { continue; } else if(strpos($href, "#") !== false) { continue; } else if(substr($href, 0, 11) == "javascript:") { continue; } // I need to change this below somehow, the two arrays are identical, // What I want to do is move $href(crawled) to $alreadyCrawled and remove it from $crawling // I also want to check if the current $href (crawling) is in $alreadyCrawled and if it is skip crawling and move on to the next one. //In essence I want to prevent the crawler from crawling anything already crawled in order to speed up the crawler. $href = createLink($href, $url); if(!in_array($href, $alreadyCrawled)) { $alreadyCrawled[] = $href; $crawling[] = $href; } else { continue;} echo $href . "<br>"; } array_shift($crawling); foreach($crawling as $site) { followLinks($site); } } $startUrl = "https://imagimedia.co.za"; followLinks($startUrl); ?>
Result.
https://imagimedia.co.za/../seo/ https://imagimedia.co.za/../pages/marketing.html https://imagimedia.co.za/../pages/web-design.html http://imagimedia.co.za/ https://imagimedia.co.za/../website-cost-quote.php https://imagimedia.co.za/../blogs/history.html https://imagimedia.co.za/../blogs/payment.html https://imagimedia.co.za/../blogs/copy.html https://imagimedia.co.za/../blogs/cycle.html https://imagimedia.co.za/../blogs/information.html https://imagimedia.co.za/../blogs/privacy.html https://imagimedia.co.za/../blogs/terms.html https://imagimedia.co.za/../blogs/content-is-king.html https://imagimedia.co.za/../blogs/pretoria-north-web-design.html https://imagimedia.co.za/../blogs/annlin-web-design.html https://imagimedia.co.za/../blogs/ http://imagimedia.co.za http://imagimedia.co.za/../seo/ http://imagimedia.co.za/../pages/marketing.html http://imagimedia.co.za/../pages/web-design.html http://imagimedia.co.za/../website-cost-quote.php http://imagimedia.co.za/../blogs/history.html http://imagimedia.co.za/../blogs/payment.html http://imagimedia.co.za/../blogs/copy.html http://imagimedia.co.za/../blogs/cycle.html http://imagimedia.co.za/../blogs/information.html http://imagimedia.co.za/../blogs/privacy.html http://imagimedia.co.za/../blogs/terms.html http://imagimedia.co.za/../blogs/content-is-king.html http://imagimedia.co.za/../blogs/pretoria-north-web-design.html http://imagimedia.co.za/../blogs/annlin-web-design.html http://imagimedia.co.za/../blogs/ I know I am also going to have to exclude duplicates created by the http and https pages. But that is not my main issue. Hello, I have a family website with an address book. I have it set so that you can select people based on who's family they are part of. So everyone in the family is part of my grandmother so when you select her group then everyone should display. Then I have it so that when you select my aunt or uncle then it will display only their families and so forth. so everyone except my grandmother has more than one family_id. I have a master_id specific to each master_name, then each master_id can have up to 3 family_id's. my issue is when I select all (my grandmother's group) i need it to group by my aunt's and uncle's families. and right now it is just in order of how I entered it into the database. My query selects all family_id's that = my $_POST[fam_id] from a dropdown list. So when I select my grandmother's group it will only return family_id "1". but i need to group by family_id 2-15, whichever is assigned to my aunt or uncle under my grandmother. since the query does not ask for it obviously i cannot sort by it. If I ask for everyone, grouped by family_id then I cannot select only by aunt or uncle as well. i'm at a total loss. please help. Here is my basic query right now: $sel_id= "SELECT master_id FROM master_family where family_id = '$_POST[fam_id]' ORDER BY master_id"; Please know this is my first website so I am very new to this and hope my question is not too lame. Can someone tell me the best way to group elements in an XML file? Code: [Select] <item> <title>Event 1</title> <dc:date>2010-09-25T01:00:00+01:00</dc:date> <dc:date>2010-10-02T01:00:00+01:00</dc:date> <dc:date>2010-10-09T01:00:00+01:00</dc:date> </item> <item> <title>Event 2</title> <dc:date>2010-09-25T01:00:00+01:00</dc:date> <dc:date>2010-10-02T01:00:00+01:00</dc:date> <dc:date>2010-10-09T01:00:00+01:00</dc:date> </item> Above is an example of what im trying to do and below is what i want the output to be Code: [Select] 25th September 2010 Event 1 Event 2 2nd October 2010 Event 1 Event 2 And so on, can anyone point me in the right direction on where to start looking to do something like this in PHP. Thanks Garry hi, i have a field for price that gets returned. is there a way to do ORDER BY 'category' so that i can have tally at the bottom of each category that adds all the prices together? Hello everyone, Could be possible someone help me on this code please? I need to group and sort $search_query. They are the keywords extracted from $_SERVER[HTTP_REFERER] (referer in the query). Thank you in advance. Code: [Select] $query = ("SELECT referer, browser_ip, date, customers_id, counter, browser_id, browser_language FROM visitors WHERE SUBSTRING(browser_language,1,1) != '[' ORDER by date DESC"); $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $referer = $row[0]; IF($referer) { PREG_MATCH("/[\&\?]q=([^&]*)/", $referer, $matches); $search_query = RAWURLDECODE($matches[1]); $search_query = STR_REPLACE("+", " ", $search_query); } ........................ I have multiple arrays containing data for each entry. What I am trying to do is group each item in the array by the date which is also in an array. Where do I start?? Code: [Select] array 'pubDate' => string 'Mon, 15 Feb 10 00:00:00 +0000' (length=29) 'title' => object(SimpleXMLElement)[6] 'description' => object(SimpleXMLElement)[7] 'guid' => string 'http://www.dailyinfo.co.uk/events.php?colname=Events&period=7&eventday=25&eventmonth=9&eventyear=2010#72741' (length=107) 'link' => string 'http://www.dailyinfo.co.uk/events.php?colname=Events&period=7&eventday=25&eventmonth=9&eventyear=2010#72741' (length=107) array 'date' => array 0 => string '2010-09-25T01:00:00+01:00' (length=25) 1 => string '2010-10-02T01:00:00+01:00' (length=25) ------------------------------------------------------------------------------------------------------------------- array 'pubDate' => string 'Fri, 26 Feb 10 00:00:00 +0000' (length=29) 'title' => object(SimpleXMLElement)[5] 'description' => object(SimpleXMLElement)[8] 'guid' => string 'http://www.dailyinfo.co.uk/events.php?colname=Events&period=7&eventday=1&eventmonth=10&eventyear=2010#73266' (length=107) 'link' => string 'http://www.dailyinfo.co.uk/events.php?colname=Events&period=7&eventday=1&eventmonth=10&eventyear=2010#73266' (length=107) array 'date' => array 0 => string '2010-09-25T01:00:00+01:00' (length=25) 1 => string '2010-09-30T01:00:00+01:00' (length=25) ------------------------------------------------------------------------------------------------------------------- |