Jump to content

Archived

This topic is now archived and is closed to further replies.

markspec87

Record Retrieval from Database

Recommended Posts

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.

Share this post


Link to post
Share on other sites
SELECT * FROM table ORDER BY newsdate DESC LIMIT 2

Just another note: "date" is a bad column title because it's a MySQL and PHP keyword.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[code]
if($result && mysql_num_rows($result) > 0) // error checking
{
     while($row = mysql_fetch_array($result))
     {
          echo $row['column1'];
          echo $row['column2'];
     }
}
[/code]

Share this post


Link to post
Share on other sites
[!--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.

Share this post


Link to post
Share on other sites
SELECT * FROM table ORDER BY newsdate DESC LIMIT 1,1

That will get record #2

The limit clause uses an offset/count format.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.