PHP - Grouping By Column To Get The Oldest Entry
Basically I want to group a bunch of rows together to get the oldest entry which is a unix time stamp, so I can compare that to another variable.
I would like to know if this query is correct to get the oldest entry in "table.replyUnixTime"?
SELECT table.*, MAX(table.replyUnixTime) AS lastReply FROM table GROUP BY table.replyId ORDER BY lastReply DESCThanks Similar TutorialsGood day I have three tables - receiving - shipping and stock movement. everyday i transfer into stock movent the sum of receining with date - havein a stock movent entry per day - I also at end of day update with shipping for that day, in stock table I calculate ne stock level. my problem is that when three days bac i stil have stock i need to start subtracting from oldest entry first till it reaches 0 the move over to second eldest? i have no idea where to start or how to achieve this Code: [Select] $db_connect = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql_get = "SELECT DISTINCT category FROM con"; $sql_run = mysqli_query($db_connect, $sql_get) or mysqli_error($db_connect); $sql_assoc = mysqli_fetch_assoc($sql_run); while($sql_assoc = mysqli_fetch_assoc($sql_run)){ echo $sql_assoc['category']; } From the column "category" I get printed 5 distinct entries, though the SQL statement itself does print out 6 distinct entries in MySQL, which is the right one. Just wondering why does the while loop leave out one entry? Also in the array is the "category" identifier necessary since it is identified in the SQL statement already? How would it look differently? Alright, wasn't quite sure how to summarize this in the title, but I want to: Check if a user status is "active" or not based on the UserName input. I have a table witch holds: Code: [Select] VarChar Username Var CharPassWord int Active Ted TedsPW 1 something like the above(assuming it formatted correctly. In my php script I will want to input a variable for Username to check for: inputUN in this example would be "Ted". $UserNameToCheck = $_GET['inputUN']; Then I want to check for that UserName in the database, if it exists, I want pull the value for the "Active" field for just that UserName and echo it. Thanks for any help. Hi everyone, im new to php, iv just created a news feed where i have a limit of 10 to be echoed out. but i want the update form to delete the oldest post as it updates... how would i do this please I am using php to upload a file to my server, and at the same time inserting the files name and url into my mysql database.
$sql = "UPDATE uploads SET name = '$name', url='$target_path'"; $statement = $dbh->prepare($sql); $statement->execute();This is working, however, when I upload a new file, rather than making a new entry in my database, it just overwrites the first one. I'm quite new at mysql so was wondering how I would make it add new entrys instead of overwriting the current one? Now im trying to do one more thing, that if I make another row with the value 2 for the type of news it is, I want to automatically turn the oldest news with the value 2 in the type column to '3'. Is there any kind of query to update the row to '3' if a row is found with the same value and update the oldest news that was posted with the value 2. Also, I want it to work that if only there are 3 rows in there with the same value. Id be happy if I could get some help. Is there anything that can do it like that? or can that not be created? Good morning. I need to subtract stock levels from oldest stock first then to the next date. It is allowed to move into negative values. example 01-10 stock in 10 stock out 5 - stock count 5 02-10 stock in 10 stock out 7 stock count ... here we need to subtract the 7 from previous days 5 til it reches 0 then stock in subtraction 01-10 stock =0 02-10 stock = 8 --- as 7 -5 gives me -2 in incoming stock is 10 leaving me with stock count of 8. 03-10 stock in 8 stock out 21 02-10 stck level must be 0 03-10 stock lever now is 8-14 = -6 and so on below is my code. $lq_in = new ListQuery('stock_audit5f5795042f369'); $lq_in->addSimpleFilter('name', '%PEPPER yellow%', 'LIKE' ); //$lq_in->addSimpleFilter('product_id', $product_id, '='); $lq_in->setOrderBy('date_entered'); $res_in = $lq_in->fetchAll(); $StockArray = []; foreach($res_in as $out_rec) { /*$upd_out = array(); $upd_out['stock_out_done'] = 0; $out_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $out_rec->getField('id')); $aud_upd_out = RowUpdate::for_result($out_rec_u); $aud_upd_out->set($upd_out); $aud_upd_out->save(); continue; */ $stock_out = $out_rec->getField('stock_out'); $stock_out_done = $out_rec->getField('stock_out_done'); $date_entered = $out_rec->getField('date_entered'); $product_id = $out_rec->getField('product_id'); //echo '<pre>'; // print_r($out_rec->row); $StockItems[] = $out_rec->row; //$stock_done = 0; /* foreach($res_in as $in_rec) { $upd = array(); if($stock_out_new > $in_rec->getField('stock_level')) { $upd['stock_level'] = 0; $stock_out_new = $stock_out_new-$in_rec->getField('stock_level'); $stock_done = $in_rec->getField('stock_level'); } elseif ($stock_out_new == $in_rec->getField('stock_level')) { $upd['stock_level'] = 0; $stock_out_new = 0; $stock_done = $stock_out; } elseif($stock_out_new < $in_rec->getField('stock_level')) { $upd['stock_level'] = $in_rec->getField('stock_level')-$stock_out_new; $stock_out_new = 0; $stock_done = $stock_out; } else { continue; } $in_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $in_rec->getField('id')); $aud_upd = RowUpdate::for_result($in_rec_u); $aud_upd->set($upd); $aud_upd->save(); if($stock_out_new == $stock_done) break; } $upd_out = array(); $upd_out['stock_out_done'] = $stock_done; $out_rec_u = ListQuery::quick_fetch('stock_audit5f5795042f369', $out_rec->getField('id')); $aud_upd_out = RowUpdate::for_result($out_rec_u); $aud_upd_out->set($upd_out); $aud_upd_out->save(); */ } function GetFirstItemWithStockKey($StockItemsarrayk = null){ if($StockItemsarrayk != null){ foreach($StockItemsarrayk as $key => $value){ if(((int) $StockItemsarrayk[$key]['stock_level']) > 0){ return $key; } } } } function SetFirstItemWithStock($StockItemsarray = null){ if($StockItemsarray != null){ foreach($StockItemsarray as $key => $value){ if(((int) $StockItemsarray[$key]['stock_level']) > 0){ return $StockItemsarray[$key]; } } } } $remainder = 0; $pkey = ""; $StockLevelKey = 0; $StockIn = []; $StockOut = []; $InStock = []; $NewStockItems = $StockItems; $ArrayKeys = []; foreach($StockItems as $key => $value){ $StockIn[$key] = (int) $StockItems[$key]['stock_in']; $StockOut[$key] = (int) $StockItems[$key]['stock_out']; $InStock[$key] = (int) $StockItems[$key]['stock_level']; $ArrayKeys[] = (int)$key; } //var_dump($InStock); foreach($NewStockItems as $key => $value){ if($key < 1){ if($StockIn[$key] > 0 && $StockOut[$key] == 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] + $StockIn[$key]); } if($StockIn[$key] == 0 && $StockOut[$key] > 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - $StockOut[$key]); } if($StockIn[$key] > 0 && $StockOut[$key] > 0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - $StockOut[$key] + $StockIn[$key]); $StockItems[$key]['stock_out'] = 0; } } if($key > 0){ $previousWithStockItem = SetFirstItemWithStock($StockItems); $previousItemWithStockKey = GetFirstItemWithStockKey($StockItems); // echo "<pre>"; // print_r($previousWithStockItem); // var_dump($StockIn[$key]); echo " --IN"; // var_dump($InStock[$key]); echo " --- current"; // var_dump($StockOut[$key]); echo " --- OUT"; while($StockOut[$key] > 0){ if($StockOut[$key] > 0 && $previousWithStockItem['stock_level'] > 0){ $Counter = 0; $maxIteration = 0; for($Counter = $previousWithStockItem['stock_level']; $Counter >= 0; $Counter--){ $StockItems[$previousItemWithStockKey]['stock_level'] = $Counter; if($Counter == 0){ $StockOut[$key] = $StockOut[$key] - $maxIteration; } $maxIteration++; } } if((((int) $StockItems[$key]['stock_level'] < 0) || ((int) $StockItems[$key]['stock_level'] === 0))&& ($StockIn[$key] > 0)){ $valueTotal = $StockItems[$key]['stock_level'] + $StockIn[$key]; $StockItems[$key]['stock_level'] = $valueTotal; } echo "<hr/>"; echo (int) $StockOut[$key]; echo "<br/>"; echo (int) $StockItems[$key]['stock_level']; echo "<br/>"; echo "<hr/>"; if(((int) $StockOut[$key] > 0) && ((int) $StockItems[$key]['stock_level'] > 0) && ((int) $StockItems[$key]['stock_level'] > $StockOut[$key])){ $newStockLevel = $StockItems[$key]['stock_level'] - $StockOut[$key]; echo $newStockLevel; $StockItems[$key]['stock_level'] = $newStockLevel; $StockItems[$key]['stock_out'] = 0; $StockOut[$key] = 0; } if((((int) $StockItems[$key]['stock_level'] < 0) || ((int) $StockItems[$key]['stock_level'] === 0))&& ($StockIn[$key] > 0)){ $valueTotal = $StockItems[$key]['stock_level'] + $StockIn[$key]; echo $valueTotal; $StockItems[$key]['stock_level'] = $valueTotal; } } } } echo "<table><tr><td><pre>"; print_r($NewStockItems); echo "</pre></td><td><pre>"; print_r($StockItems); echo "</pre></td></table>"; /* if($StockIn[$key] > 0 && $StockOut[$key] >0 && $InStock[$key] == 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] + ($StockIn[$key] + $StockOut[$key])); $StockOut[$key] = 0; $StockItems[$key]['stock_out'] = 0; } if($StockIn[$key] != 0 && $StockOut[$key] != 0 && $InStock[$key] != 0){ $StockItems[$key]['stock_level'] = ($InStock[$key] - ($StockOut[$key] + $StockIn[$key])); $StockOut[$key] = 0; $StockItems[$key]['stock_out'] = 0; }*/ /** @Rule 1 # Stockin has value and stock_out = 0 and stock_level = 0 and stock_out_done = null, actualstock to show actual stock level; # */ /*if($StockCalculation[$Skey]['stock_out'] >= $StockItems[$key]['stock_level']){ $StockItems[$key]['stock_out'] = ($StockItems[$key] - 1); $StockItems[$key]['stock_level'] = ($StockItems[$key]['stock_level'] - 1); // If StockOut == 0 next StockOutItem if($StockCalculation[$Skey]['stock_out'] == 0){ $remainder = 0; continue; }elseif($StockItems[$key]['stock_level'] == 0){ //CurrentInStock == 0 then continue to next CurrentItem $remainder = $StockItems[$key]['stock_out']; continue(2); } } $CurrentStockIn = $StockItems[$key]['stock_in']; $CurrentStockOut = $StockItems[$key]['stock_out']; $CurrentInStock = $StockItems[$key]['stock_level']; if($key == 0){ if($CurrentStockIn > 0 && $CurrentStockOut === 0 && $CurrentInStock == 0){ $CurrentInStock = $CurrentStockIn; //Query update stock level set = stock_in //"UPDATE STOCK SET stock_level = {$CurrentStockIn} where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentStockIn; } if($CurrentStockIn != 0 && $CurrentStockOut != 0 && $CurrentInStock == 0){ //Query Update Stocklevel if stock_out > 0 and stock_level = 0 //"UPDATE STOCK SET stock_level = "+($CurrentStockIn - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; if($CurrentStockIn > $CurrentStockOut && $CurrentStockOut == 0){ $StockItems[$key]['stock_out'] = 0; $StockItems[$key]['stock_level'] = $CurrentInStock = $CurrentStockIn - $CurrentStockOut; } if($CurrentStockOut > $CurrentStockIn){ $StockItems[$key]['stock_level'] = $CurrentInStock = $CurrentInStock - $CurrentStockOut; } } if($CurrentInStock != 0 && $CurrentStockOut > 0){ //If Current in stock below 0 and stock out > 0 then negative more //"UPDATE STOCK SET stock_level = "+($CurrentInStock - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentInStock = ($CurrentInStock - $CurrentStockOut); $StockItems[$key]['stock_out'] = 0; } if($CurrentInStock != 0 && $CurrentStockIn > 0){ //If Current in stock below 0 and stock out > 0 then negative more //"UPDATE STOCK SET stock_level = "+($CurrentInStock - $CurrentStockOut) + "where id = {$StockItems[$key]['id']}"; $StockItems[$key]['stock_level'] = $CurrentInStock = ($CurrentInStock + $CurrentStockIn); } // Run row update for first item }else{ foreach($StockCalculation as $Skey => $Sval){ $NextStockOut = $Sval['stock_out']; $NextStockIn = $Sval['stock_in']; $NextStockLevel = $Sval['stock_level']; if($Skey > 0 && $key > 0){ // print_r($NextStockOut); for($i = $NextStockOut; $i >= -1; $i--){ if($NextStockOut > 0){ if($NextStockOut > 0){ /* if($StockItems[$StockLevelKey]['stock_level'] != 0){ $StockItems[($StockLevelKey)]['stock_level'] = ($StockItems[($StockLevelKey)]['stock_level'] - 1); //$StockItems[($Skey-1)]['stock_out'] = ($StockItems[($Skey-1)]['stock_out'] -1); } if($StockItems[($Skey-1)]['stock_level'] != 0){ $StockItems[($Skey-1)]['stock_level'] = ($StockItems[($Skey-1)]['stock_level'] - 1); } } } $NextStockOut = ($NextStockOut -1); if($NextStockOut != 0){ $StockItems[$Skey]['stock_out'] = 0; break; } } } unset($StockCalculation[$Skey]); } }/* */
Hi I have the following script to show images from a directory and make thumbs , but I would like to know how to sort the images from newest to oldest and how to implement it in this script
I'm a rookie at this...
Many Thanks in Advance!
<?php # SETTINGS $max_width = 800; $max_height = 600; $per_page = 10; $page = $_GET['page']; $has_previous = false; $has_next = false; function getPictures() { global $page, $per_page, $has_previous, $has_next; if ( $handle = opendir(".") ) { $lightbox = rand(); echo '<ul id="pictures">'; $count = 0; $skip = $page * $per_page; if ( $skip != 0 ) $has_previous = true; while ( $count < $skip && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) $count++; } $count = 0; while ( $count < $per_page && ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { // make the thumbs directory if it doesn't already exist if ( ! is_dir('thumbs') ) { mkdir('thumbs'); } // make a thumbnail if it doesn't already exist if ( ! file_exists('thumbs/'.$file) ) { makeThumb( $file, $type ); } // create a link to $file, add the thumbnail echo '<li><a href="' . $file . '">'; echo '<img src="thumbs/'.$file.'" alt="" /></a></li>'; $count++; echo substr($file,strlen($folder),strpos($file, '.')-strlen($folder)); } } echo '</ul>'; while ( ($file = readdir($handle)) !== false ) { if ( !is_dir($file) && ($type = getPictureType($file)) != '' ) { $has_next = true; break; } } } } function getPictureType($file) { $split = explode('.', $file); $ext = $split[count($split) - 1]; if ( preg_match('/jpg|jpeg/i', $ext) ) { return 'jpg'; } else if ( preg_match('/png/i', $ext) ) { return 'png'; } else if ( preg_match('/gif/i', $ext) ) { return 'gif'; } else { return ''; } } function makeThumb( $file, $type ) { global $max_width, $max_height; if ( $type == 'jpg' ) { $src = imagecreatefromjpeg($file); } else if ( $type == 'png' ) { $src = imagecreatefrompng($file); } else if ( $type == 'gif' ) { $src = imagecreatefromgif($file); } if ( ($oldW = imagesx($src)) < ($oldH = imagesy($src)) ) { $newW = $oldW * ($max_width / $oldH); $newH = $max_height; } else { $newW = $max_width; $newH = $oldH * ($max_height / $oldW); } $new = imagecreatetruecolor($newW, $newH); imagecopyresampled($new, $src, 0, 0, 0, 0, $newW, $newH, $oldW, $oldH); if ( $type == 'jpg' ) { imagejpeg($new, 'thumbs/'.$file); } else if ( $type == 'png' ) { imagepng($new, 'thumbs/'.$file); } else if ( $type == 'gif' ) { imagegif($new, 'thumbs/'.$file); } imagedestroy($new); imagedestroy($src); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="en-US"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UFT-8" /> <title>Pictures</title> <link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" /> <style type="text/css"> body { width:780px; margin:0 auto; } #pictures li { float:left; height:<?php echo ($max_height + 10); ?>px; list-style:none outside; width:<?php echo ($max_width + 10); ?>px; text-align:center; } img { border:0; outline:none; } .prev { float:left; } .next { float:right; } </style> </head> <body> <?php getPictures(); ?> <div style="clear:both"></div> <?php if ( $has_previous ) echo '<p class="prev"><a href="?page='.($page - 1).'">← Previous Page</a></p>'; if ( $has_next ) echo '<p class="next"><a href="?page='.($page + 1).'">Next Page →</a></p>'; ?> <div style="clear:both"></div> <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> </body> </html> Can there be an auto remove oldest message from mailbox so can always get new.
I see the max is 50, kinda sucks to delete manually to make room for more.
Can't you just limit these to 49 by always removing the oldest one? To ensure can get any new messages.
I have a posting system worked out, as well as my database configured to my linking.. But as of right now, my posts are posted from oldest to newest, having users scroll down or go to the next page to see the most recent post.
How would I "flip" that around and make my posts start from newest to oldest by its date/time (Which is stored in the database)?
Thanks!
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. Hello all, Need a little help with grouping and summing using an array. I can't do this directly from the database because the vendor package we are using (Tivoli Data Warehouse) stores date in a proprietary format as a CHAR in the database and in GMT so I have to get the data first and then manipulate the date to get it human readable and in the right EST date. I have my query (and my date conversion) from the database returning the data in a format that looks like this: The reason each date has the service repeated is because it was selected from the database by hour (needed to convert Tivoli's weird timestamp and use of GMT) Service TX_Count Date ------------------------------------------------------------------------------------------- Service1 23451 2010-01-01 Service1 93874 2010-01-01 Service1 82363 2010-01-01 Service1 56245 2010-01-02 Service1 73453 2010-01-02 Service1 18965 2010-01-02 I have successfully gotten the data in to an array and I can group by date and then sum the tx_count, or I can group the services and sum the tx_count. What I really need to be able to do is to get the transaction counts by service by day so that I would get something like this as a result Service1 2010-01-01 199688 Service1 2010-01-02 148663 So I need to group by service and then date and then sum it all out of the array. Any advice and direction is appreciated 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 Hello,
I was wondering if maybe someone could help me on this. I am having trouble with this query. I need to send an email to the users but group all the records related to that user instead of sending one email per record to the user. I hope this makes sense. Here is the code I have so far. All records are being displayed but how can I get all the records for each user (infant_specialist field) send one email and then go to the next user and send the other email and so on.
Thank you for your help
$conn = mysqli_connect('localhost','root','','dbname'); $sql = "SELECT case_no, client_name, infant_specialist.full_name, infant_specialist.is_email FROM ies_clients INNER JOIN infant_specialist ON ies_clients.infant_specialist = infant_specialist.is_id WHERE (date_closed IS NULL OR date_closed >= DATE_FORMAT(NOW() ,'%Y-%m-01')) ORDER BY client_name ASC"; $q = mysqli_query($conn,$sql); //echo mysqli_num_rows($q) . '<br/>'; while($row = mysqli_fetch_array($q) ){ echo $row['client_name'] . ' --- ' , $row['full_name'] . ' --- ' . $row['is_email'] . '<br/>'; } Edited by stivenbr, 07 October 2014 - 02:05 PM. 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? Often in the very beginning of index.php, I will define a bunch of constants. To make sure I can quickly identify them as being one of my defined constants, I will often include some sort of prefix.
define ('xzy_somecontant',123); define ('xzy_anothercontant',321);Sometimes I have a bunch of constants that are related; define ('xzy_id_for_page1',123); define ('xzy_id_for_page2',231); define ('xzy_id_for_page3',312);It would be nice to somehow group them into say "xzy_page_ids", and then access them by some index such as "page1" or "1" (or whatever makes sense for the given naming structure). Is this possible? Is there another defacto way of doing so such as a static class or something? Thanks 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); } ........................ Hey everyone, I have a database for projects and each entry has one or more project type category that it falls into. The values are separated with a semi-colon to make the distinction. I've used the following code to output the data onto the page: Code: [Select] $sql = "SELECT project_type FROM projects ORDER BY project_type"; $result = mysql_query($sql); while ($rs = mysql_fetch_array($result)) { $database_value = $rs['project_type']; $array = explode(';', $database_value); foreach($array as $key => $value){ echo " ".$value."<br />"; } } This outputs the following: Code: [Select] Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Agriculture Export Development Agriculture Impact Assessments Impact Studies Agriculture M & E Agriculture Private Sector Development Corporate and Public Governance Corporate and Public Governance Corporate and Public Governance In PHP, how can I group these values together, similar to SQL's GROUP BY method? I've tried grouping it in the query but some of the data goes lost because it must be exploded first. Can anybody help? Thanks in advance! Karen 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) ------------------------------------------------------------------------------------------------------------------- I'm trying to dynamically group a range of rows using PHPSpreadsheet and having a lot of trouble thinking through the logic. My code so far looks like this: $worksheet = $spreadsheet->getActiveSheet(); // Get the highest row number and column letter referenced in the worksheet $highestRow = $worksheet->getHighestRow(); // e.g. 10 $highestColumn = $worksheet->getHighestColumn(); // e.g 'F' // Increment the highest column letter $highestColumn++; $job_num_chk = ''; $grp_start_row = ''; //format the inserted records for ($row = 2; $row <= $highestRow; ++$row) { //$spreadsheet->getActiveSheet()->getRowDimension($row)->setRowHeight(53); for ($col = 'A'; $col != $highestColumn; ++$col) { $spreadsheet->getActiveSheet()->getStyle($col . $row)->getAlignment()->setVertical(\PhpOffice\PhpSpreadsheet\Style\Alignment::VERTICAL_TOP); $spreadsheet->getActiveSheet()->getStyle($col . $row)->getAlignment()->setHorizontal(\PhpOffice\PhpSpreadsheet\Style\Alignment::HORIZONTAL_LEFT); if ($col == 'B') { $cur_job_num = $spreadsheet->getActiveSheet()->getCell($col . $row)->getValue(); //get current job number //check if job number is different if ( $job_num_chk !== $cur_job_num ) { $spreadsheet->getActiveSheet()->insertNewRowBefore($row, 1); //insert dividing row //set dividing row to black $spreadsheet->getActiveSheet()->getStyle('A'.$row.':N'.$row)->getFill() ->setFillType(\PhpOffice\PhpSpreadsheet\Style\Fill::FILL_SOLID) ->getStartColor()->setARGB('000000'); $job_num_chk = $cur_job_num; //update job number } } } } This line: $grp_start_row = ''; Is where I'm hitting a mental wall...here's what the spreadsheet looks like so far:
I want to be able to group the rows 101-105 in that example like below:
I need to be able to determine where the start row is and the end row is in order to use the grouping feature (https://phpspreadsheet.readthedocs.io/en/latest/topics/recipes/#groupoutline-a-row) Thanks everyone. |