last

Laravel, get last insert id using Eloquent

匿名 (未验证) 提交于 2019-12-03 02:11:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I'm currently using this code to insert data in a table: public function saveDetailsCompany () { $post = Input :: All (); $data = new Company ; $data -> nombre = $post [ 'name' ]; $data -> direccion = $post [ 'address' ]; $data -> telefono = $post [ 'phone' ]; $data -> email = $post [ 'email' ]; $data -> giro = $post [ 'type' ]; $data -> fecha_registro = date ( "Y-m-d H:i:s" ); $data -> fecha_modificacion = date ( "Y-m-d H:i:s" ); if ( $data -> save ()) { return Response :: json ( array ( 'success' => true ), 200 ); } } And I want

MySQL ON DUPLICATE KEY - last insert id?

匿名 (未验证) 提交于 2019-12-03 02:08:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I have the following query: INSERT INTO table (a) VALUES (0) ON DUPLICATE KEY UPDATE a=1 I want the ID of either the insert or the update. Usually I run a second query in order to get this as I believe insert_id() only returns the 'inserted' ID and not the updated ID. Is there a way to INSERT/UPDATE and retrieve the ID of the row without running two queries? 回答1: Check this page out: http://dev.mysql.com/doc/refman/5.0/en/insert-on-duplicate.html At the bottom of the page they explain how you can make LAST_INSERT_ID meaningful for updates by

How to get the last month data and month to date data

匿名 (未验证) 提交于 2019-12-03 02:06:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Need help in writing the query to get the last month data as well as month to date data. If today's date is Mar 23 2011, I need to retrieve the data from last month and the data till todays date(means Mar 23 2011). If date is Apr 3 2011, data should consists of March month data and the data till Apr 3rd 2011. Thanks, Shahsra 回答1: Today including time info : getdate() Today without time info : DATEADD(DAY, DATEDIFF(day, 0, getdate()), 0) Tomorrow without time info : DATEADD(DAY, DATEDIFF(day, 0, getdate()), 1) Beginning of current month :

Delete last commit in bitbucket

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I made a mistake and I don't know how to delete my latest push in the repository. I pull the latest updates of the app but it has conflicts and I push it to repository. How to delete my last commit? Or how to fix it? 回答1: In the first place, if you are working with other people on the same code repository, you should not delete a commit since when you force the update on the repository it will leave the local repositories of your coworkers in an illegal state (e.g. if they made commits after the one you deleted, those commits will be invalid

C++ Compare and replace last character of stringstream

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: I would like to check the following: If the last character appended to the stringstream is a comma. If it is remove it. std :: stringstream str ; str << "[" //loop which adds several strings separated by commas str . seekp (- 1 , str . cur ); // this is to remove the last comma before closing bracket str << "]" ; The problem is if nothing is added in the loop, the opening bracket is removed from the string. So I need a way to check whether the last character is a comma. I did that like this: if ( str . str (). substr ( str . str ()

MySQL Query to select data from last week?

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: Hi I have a table with a date field and some other information. I want to select all entries from the past week, (week start from Sunday). table values: id date 2 2011 - 05 - 14 09 : 17 : 25 5 2011 - 05 - 16 09 : 17 : 25 6 2011 - 05 - 17 09 : 17 : 25 8 2011 - 05 - 20 09 : 17 : 25 15 2011 - 05 - 22 09 : 17 : 25 I want to select all ids from last week, expected output is 5, 6, 8. (id 2 not in last week, and id 15 is in current week.) How to write and SQL Query for the same. 回答1: SELECT id FROM tbl WHERE date >= curdate () - INTERVAL

Java list&#039;s .remove method works only for second last object inside for each loop

匿名 (未验证) 提交于 2019-12-03 02:03:01
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I am seeing a weird behavior. List li = new ArrayList(); li.add("a"); li.add("b"); li.add("c"); li.add("d"); li.add("e"); for(String str:li){ if(str.equalsIgnoreCase("d")){ li.remove(str); //removing second last in list works fine } } But if i try to remove any other than second last in the list, i get ConcurrentModificationException. It came to my attention while reading "Oracle Certified Associate Java SE 7 Programmer Study Guide 2012" which incorrectly assumes that .remove() always works with an example of removing the second last in the

selecting rows in the last 5 minutes using unix time stamp

匿名 (未验证) 提交于 2019-12-03 02:00:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Iam trying to figure out whetere data was save to the db in the las 5 minutes. SELECT COUNT(id), DATE_FORMAT(`timestamp`, '%Y-%m-%d %H:%i') FROM `table` WHERE `timestamp` >= CURRENT_TIMESTAMP - INTERVAL 5 MINUTE timestamp is a unix timestamp (millisecs from 1970). doesn't work, I get null num_rows instead of 0 and if I use if (!isset($resultHistory->num_rows) || !$resultHistory->num_rows) to do actions, the code does not enter the loop.. I also tried SELECT COUNT(id), DATE_FORMAT(`timestamp`, '%Y-%m-%d %H:%i') FROM `table` WHERE DATE_FORMAT(

extract last 10 minutes from logfile [duplicate]

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 由 翻译 强力驱动 问题: This question already has an answer here: Filter log file entries based on date range 3 answers Trying to find a simple way for watching for recent events (from less than 10 minutes), I've tried this: awk "/^$(date --date=" - 10 min " " +% b % _d % H :% M ")/{p++} p" / root / test . txt but it doesn't work as expected... Log files are in form : Dec 18 09 : 48 : 54 Blah Dec 18 09 : 54 : 47 blah bla Dec 18 09 : 55 : 33 sds Dec 18 09 : 55 : 38 sds Dec 18 09 : 57 : 58 sa Dec 18 09 : 58 : 10 And so on ... 回答1: You can match the date

How to sort NULL values last using Eloquent in Laravel

匿名 (未验证) 提交于 2019-12-03 01:59:02
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: I've got a many to many relationship between my employees and groups table. I've created the pivot table, and all is working correctly with that. However, I've got a sortOrder column on my employees table that I use to determine the order in which they display. Employee with a value of 1 in the sortOrder column should be first, value of 2 should be second, so on. (Or backwards if sorted descending) The sortOrder column is a integer column that allows null values. I've set up my group model to sort the employees by the sort column, but I've