lovephp Posted November 7, 2012 Share Posted November 7, 2012 guys how do i display records which is newly added or updated on top? $result = mysql_query("SELECT * FROM table"); Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/ Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 What is your table structure? You'll need a column which stores the time they are last updated. Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390888 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) i do this mysql_query("SELECT id, randid, center, customer_name, home_phone, time, approval * FROM table ORDER BY DESC"); and i get blank page why? Edited November 7, 2012 by lovephp Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390889 Share on other sites More sharing options...
AyKay47 Posted November 7, 2012 Share Posted November 7, 2012 i do this mysql_query("SELECT id, randid, center, customer_name, home_phone, time, approval * FROM table ORDER BY DESC"); and i get lank page why? Jesi asked for your table structure, which would help us solve your problem. You will need to supply that information before we can really help you. If you have a unique column that is auto_increment, you can order the results by that column descending. As to why you are seeing a blank page, in your query you are not descending by a column and you are misusing the * asterisk symbol, therefore the SQL syntax is invalid and an error is being triggered. You should have error_handling set to -1 and display_errors set to on. Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390891 Share on other sites More sharing options...
Barand Posted November 7, 2012 Share Posted November 7, 2012 Because your query syntax is screwed up. Check value returned by mysql_error() Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390892 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 here you go -- -- Table structure for table `table` -- CREATE TABLE IF NOT EXISTS `table` ( `id` int(11) NOT NULL AUTO_INCREMENT, `customer_name` varchar(150) NOT NULL, `address` varchar(150) NOT NULL, `home_phone` varchar(12) NOT NULL, `alt_phone` varchar(12) NOT NULL, `email` varchar(100) NOT NULL, `sex` varchar(10) NOT NULL, `mortgagetype` varchar(50) NOT NULL, `propertyvalue` varchar(50) NOT NULL, `mortgagebalance` varchar(50) NOT NULL, `secondmortgage` varchar(50) NOT NULL, `monthlypayments` varchar(50) NOT NULL, `monthlypaymentstype` varchar(50) NOT NULL, `secondmortgagepayments` varchar(50) NOT NULL, `secondmortgagepaymentstype` varchar(50) NOT NULL, `interestrate` varchar(50) NOT NULL, `secondinterest` varchar(50) NOT NULL, `ltv` varchar(50) NOT NULL, `creditrating` varchar(50) NOT NULL, `misspayments` varchar(10) NOT NULL, `additionaldebts` varchar(500) NOT NULL, `penalty` varchar(50) NOT NULL, `refinanced` varchar(10) NOT NULL, `maturity` varchar(10) NOT NULL, `lender` varchar(150) NOT NULL, `employment` varchar(150) NOT NULL, `ahi` varchar(150) NOT NULL, `maritialstatus` varchar(50) NOT NULL, `bankruptcy` varchar(10) NOT NULL, `bankruptcydischarged` varchar(50) NOT NULL, `proposal` varchar(10) NOT NULL, `proposalbalance` varchar(50) NOT NULL, `ip` varchar(50) NOT NULL, `center` varchar(50) NOT NULL, `approval` varchar(50) NOT NULL, `comments` text NOT NULL, `time` int(100) NOT NULL, `status_comment` text NOT NULL, `randid` varchar(10) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `home_phone` (`home_phone`,`email`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ; -- -- Dumping data for table `table` -- Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390894 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 ok this works $result = mysql_query("SELECT id, randid, center, customer_name, center, home_phone, time, approval FROM table ORDER BY id DESC"); but how do i also show which is recent;ly updated? btw i use time() to add time Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390896 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 You'll need a column which stores the time they are last updated. Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390901 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 an example please Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390903 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 IF YOU AREN'T ALREADY USING ONE OF THOSE COLUMNS TO STORE THE LAST TIME YOU UPDATED THE ROW, ADD A DAMN COLUMN TO STORE IT!!! it's not rocket surgery1 Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390907 Share on other sites More sharing options...
AyKay47 Posted November 7, 2012 Share Posted November 7, 2012 `holdyourhand` DATETIME NOT NULL Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390908 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 got it thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390910 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 ok i added a new column like `updated` TIMESPAMP NOT NULL but everytime i update data the value in it stay 00.00.00?? Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390918 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 You have to tell it the new value, it's not automatic. Also there's no such thing as a timespamp, so... Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390920 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 how do i do it here? mysql_query("UPDATE table SET customer_name ='$cusname', address = '$address', home_phone = '$phone', alt_phone = '$altphone', email = '$email', sex = '$sex', mortgagetype = '$mortgagetype', propertyvalue ='$propertyvalue', mortgagebalance = '$mortgagebalance', secondmortgage = '$secondmortgage', monthlypayments = '$monthlypayments', monthlypaymentstype = '$monthlypaymentstype', secondmortgagepayments = '$secondmortgagepayments', secondmortgagepaymentstype = '$secondmortgagepaymentstype', interestrate = '$interest', secondinterest = '$secondinterest', ltv = '$ltv', creditrating = '$credit', misspayments = '$misspayments', additionaldebts = '$debts', penalty = '$penalty', refinanced = '$refinanced', maturity = '$maturity', lender = '$lender', employment = '$employment', ahi = '$ahi', maritialstatus = '$maritialstatus', bankruptcy = '$bankruptcy', bankruptcydischarged = '$bankruptcydischarged', proposal = '$proposal', proposalbalance = '$proposalbalance', center = '$center', comments = '$comments', approval = '$approval', status_comment = '$stcomment' WHERE id = '$id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390923 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 updated = 'time();' is this right? Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390924 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 What type is the field? You should have made it a DATETIME. If you make it a DATETIME you can use CURDATE(). Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390926 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 thanks Jess let me give it a try brb Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390927 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 im getting a blank page any idea why? status_comment = '$stcomment', updated = '".CURDATE()."' WHERE id = '$id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390931 Share on other sites More sharing options...
Barand Posted November 7, 2012 Share Posted November 7, 2012 What type is the field? You should have made it a DATETIME. If you make it a DATETIME you can use CURDATE(). DATETIME - use NOW() as this has the time element too DATE - use CURDATE() as no time element Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390934 Share on other sites More sharing options...
lovephp Posted November 7, 2012 Author Share Posted November 7, 2012 ok but why im a getting a blank page any idea? status_comment = '$stcomment', updated = '".NOW()."' WHERE id = '$id'") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390939 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Those are MYSQL functions, not PHP functions. If you're getting a blank page, it means you don't have error reporting turned on. Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390942 Share on other sites More sharing options...
Barand Posted November 7, 2012 Share Posted November 7, 2012 ok i added a new column like `updated` TIMESPAMP NOT NULL but everytime i update data the value in it stay 00.00.00?? If you define it correctly it will auto update whenever a change is made `timefield` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1390946 Share on other sites More sharing options...
AyKay47 Posted November 8, 2012 Share Posted November 8, 2012 (edited) Also there's no such thing as a timespamp, so... Yes, there is.. In this particular case I would recommend using it, since it carries nice automatic initialization and update properties with it. To add these properties to a TIMESTAMP data type field, you will need to add the CURRENT_TIMESTAMP and ON UPDATE CURRENT_TIMESTAMP attributes to the field's definition. Edited November 8, 2012 by AyKay47 Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1391028 Share on other sites More sharing options...
Barand Posted November 8, 2012 Share Posted November 8, 2012 There is definitely an echo in here! AyKay, you might want to recheck the spelling in Jessica's quote Quote Link to comment https://forums.phpfreaks.com/topic/270424-display-records-by-newly-added-or-updated-how/#findComment-1391033 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.