rh91uk Posted June 20, 2006 Share Posted June 20, 2006 HiyaI 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 Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/ Share on other sites More sharing options...
Orio Posted June 20, 2006 Share Posted June 20, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-47598 Share on other sites More sharing options...
rh91uk Posted June 20, 2006 Author Share Posted June 20, 2006 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). Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-47648 Share on other sites More sharing options...
wildteen88 Posted June 20, 2006 Share Posted June 20, 2006 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 Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-47683 Share on other sites More sharing options...
rh91uk Posted June 20, 2006 Author Share Posted June 20, 2006 [!--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 :) Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-47773 Share on other sites More sharing options...
rh91uk Posted June 21, 2006 Author Share Posted June 21, 2006 [!--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 questiona) 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 storyc) How could I implement that in PHPSorry for my n00bnessRic Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48147 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 [!--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. Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48159 Share on other sites More sharing options...
rh91uk Posted June 21, 2006 Author Share Posted June 21, 2006 Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/richard/public_html/noba/index.php on line 167Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/richard/public_html/noba/index.php on line 169Any ideas? All DB connects are in the headers..... Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48172 Share on other sites More sharing options...
wildteen88 Posted June 21, 2006 Share Posted June 21, 2006 Wheres $mysql_link being set to? Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48203 Share on other sites More sharing options...
rh91uk Posted June 21, 2006 Author Share Posted June 21, 2006 Explain...*embarrased* Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48214 Share on other sites More sharing options...
rh91uk Posted June 22, 2006 Author Share Posted June 22, 2006 as in mysql_link, do you mean the headers? Because the Database is all set up correctly ... Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48420 Share on other sites More sharing options...
rh91uk Posted June 22, 2006 Author Share Posted June 22, 2006 Ah its ok now, ive sorted it.Thanks for all of your help :) Quote Link to comment https://forums.phpfreaks.com/topic/12452-pulling-data/#findComment-48422 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.