markspec87 Posted June 6, 2006 Share Posted June 6, 2006 Hey guys,What i need to do is select the two last added articles from the table "news" and display them on my front page.I need to, say, when i have selected the 2nd last added item display only one particular column. I.e the newstext column.[a href=\"http://img339.imageshack.us/img339/3136/example0fh.jpg\" target=\"_blank\"]http://img339.imageshack.us/img339/3136/example0fh.jpg[/a]And when a new item is added to DB, the news will drop down one, and the old "2nd to last added" will drop off.I am unsure on how to select both an individual record field, like "Newstext" and also how to select say the 2nd or 3rd last added entry.Sorry for bad explanation but thats the best i can do :)hope you guys can help me out here. Ive been stuck on this for a week or so. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/ Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 SELECT * FROM table ORDER BY newsdate DESC LIMIT 2Just another note: "date" is a bad column title because it's a MySQL and PHP keyword. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42435 Share on other sites More sharing options...
markspec87 Posted June 6, 2006 Author Share Posted June 6, 2006 yeh in my actual databse is called "datum".So Say in my table on my website. What code would i use to display the 2nd last record from the column"newstext". or the 2nd last date a news page was published. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42451 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 [code]if($result && mysql_num_rows($result) > 0) // error checking{ while($row = mysql_fetch_array($result)) { echo $row['column1']; echo $row['column2']; }}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42480 Share on other sites More sharing options...
markspec87 Posted June 6, 2006 Author Share Posted June 6, 2006 [!--quoteo(post=380670:date=Jun 6 2006, 06:10 PM:name=ober)--][div class=\'quotetop\']QUOTE(ober @ Jun 6 2006, 06:10 PM) [snapback]380670[/snapback][/div][div class=\'quotemain\'][!--quotec--][code]if($result && mysql_num_rows($result) > 0) // error checking{ while($row = mysql_fetch_array($result)) { echo $row['column1']; echo $row['column2']; }}[/code][/quote]thats almost what im looking for, however this outputs all the fields in those columns. I just want to output say the 2nd last added record, or the 3rd added record on thier own.thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42502 Share on other sites More sharing options...
ober Posted June 6, 2006 Share Posted June 6, 2006 SELECT * FROM table ORDER BY newsdate DESC LIMIT 1,1That will get record #2The limit clause uses an offset/count format. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42510 Share on other sites More sharing options...
markspec87 Posted June 6, 2006 Author Share Posted June 6, 2006 I put that in but then i get this error:[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Warning: mysql_result(): Unable to jump to row 2 on MySQL result index 5 in /home/.... file.php on line 110[/quote]I definitely have the records in my DB to display so im a bit stuck. Quote Link to comment https://forums.phpfreaks.com/topic/11330-record-retrieval-from-database/#findComment-42633 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.