Jump to content

Archived

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

rh91uk

Pulling Data

Recommended Posts

Hiya

I need a bit of advice ... or maybe if some code if your feeling nice :)

I am writing a content management system, and in it, I have built a News System. But, the problem is, on the homepage I am adding a "Recent 3 News Posts", which will hopefully if I can get the concept together, pull the last 3 Added news stories.

I havent a clue how to do it though :). Can someone maybe point me in the right direction, or even if your feeling nice, write me a bit of code.

I would be greatful! :)

Thanks for help in advance,

Richard

Share this post


Link to post
Share on other sites
How do you exactly do all of this? Using Databases?
And how does the script "decide" how many new posts are new?
It's hard to answer your questions without seeing some script.

Orio.

Share this post


Link to post
Share on other sites
Sorry , should of been more clear.

We are using MYSQL.

Script wise - thats what I want to find out. I can pull the data from the database, but not thhe 3 most recent "ids". I dont know how to write the code to do it, as I am self taught, and hence never coming across this kind of situation...

The script is simple text boxes submitting to a Database (mysql).

Share this post


Link to post
Share on other sites
You can use this query which should select most recent 3 news posts:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]news_table[/color] [color=green]ORDER BY[/color] news_id [color=green]DESC[/color] LIMIT 3 [!--sql2--][/div][!--sql3--]
Obviously you'll need to change [b]news_table[/b] to the table that stores your news entries and [b]news_id[/b] to the news_id column name.

Share this post


Link to post
Share on other sites
[!--quoteo(post=386035:date=Jun 20 2006, 09:51 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 20 2006, 09:51 AM) [snapback]386035[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use this query which should select most recent 3 news posts:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]news_table[/color] [color=green]ORDER BY[/color] news_id [color=green]DESC[/color] LIMIT 3 [!--sql2--][/div][!--sql3--]
Obviously you'll need to change [b]news_table[/b] to the table that stores your news entries and [b]news_id[/b] to the news_id column name.
[/quote]

Thank you wildteen88 :)

Share this post


Link to post
Share on other sites
[!--quoteo(post=386035:date=Jun 20 2006, 09:51 AM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Jun 20 2006, 09:51 AM) [snapback]386035[/snapback][/div][div class=\'quotemain\'][!--quotec--]
You can use this query which should select most recent 3 news posts:
[!--sql--][div class=\'sqltop\']SQL[/div][div class=\'sqlmain\'][!--sql1--][span style=\'color:blue;font-weight:bold\']SELECT[/span] * [color=green]FROM[/color] [color=orange]news_table[/color] [color=green]ORDER BY[/color] news_id [color=green]DESC[/color] LIMIT 3 [!--sql2--][/div][!--sql3--]
Obviously you'll need to change [b]news_table[/b] to the table that stores your news entries and [b]news_id[/b] to the news_id column name.
[/quote]

Got another question

a) How do I convert the above statement in PHP, would:

[code]<?php
$query = "SELECT * FROM news_table ORDER BY news_id DESC LIMIT 3";
mysql_query($query, $mysql_link);
?>
[/code]

work?

b) How would I convert that query to display the Three Recent Titles, then linking it to the news story

c) How could I implement that in PHP

Sorry for my n00bness

Ric

Share this post


Link to post
Share on other sites
[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]a) How do I convert the above statement in PHP, would:

[code]CODE
<?php
$query = "SELECT * FROM news_table ORDER BY news_id DESC LIMIT 3";
mysql_query($query, $mysql_link);
?>[/code]

work?[/quote]
Yes that'll work fine!

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]b) How would I convert that query to display the Three Recent Titles, then linking it to the news story?[/quote]
A bit like this

[code]<?php

//connect to do db here

$query = "SELECT news_id, news_title FROM news_table ORDER BY news_id DESC LIMIT 3";
$result = mysql_query($query, $mysql_link);

while($row = mysql_fetch_assoc($result))
{
    echo "<a href=\"news.php?id={$row['news_id']}\">{$row['news_title']}</a><br />";
}

?>[/code]
Again in this code, change any instance of news_id, news_table and news_title to your field/table names.

Share this post


Link to post
Share on other sites
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/richard/public_html/noba/index.php on line 167

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/richard/public_html/noba/index.php on line 169

Any ideas? All DB connects are in the headers.....

Share this post


Link to post
Share on other sites
as in mysql_link, do you mean the headers? Because the Database is all set up correctly ...

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.