rebelcreek Posted February 3, 2011 Share Posted February 3, 2011 I wanting to only query the lastest post only right now i'm getting all in the database here is my code please help <? include("dbconect.php"); $getnews = mysql_query("select * from news ORDER BY id DESC"); while($r=mysql_fetch_array($getnews)){ extract($r); echo("<b>$title on $date<BR><BR>$news</b>"); } ?> Thank you for the help Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/ Share on other sites More sharing options...
requinix Posted February 3, 2011 Share Posted February 3, 2011 Lastest, huh? 1. Don't sort by ID. Sort by a date and/or time field. If you don't have one, add it. 2. Remove the while loop. 3. Click me. Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/#findComment-1169219 Share on other sites More sharing options...
rebelcreek Posted February 3, 2011 Author Share Posted February 3, 2011 I'm very new to php and I wrote that code with help from a tut can you please explain further Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/#findComment-1169222 Share on other sites More sharing options...
requinix Posted February 3, 2011 Share Posted February 3, 2011 1. What fields do you have in the news table? 2. Since you're only getting one row, don't use a while loop. Try to remove it. You still need mysql_fetch_array and the stuff inside the loop, but the while(){} you can get rid of. 3. Did you click the link? Read what it brought you to? Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/#findComment-1169228 Share on other sites More sharing options...
rebelcreek Posted February 3, 2011 Author Share Posted February 3, 2011 `id` tinyint(4) NOT NULL auto_increment, `title` text NOT NULL, `date` text NOT NULL, `news` text NOT NULL, PRIMARY KEY (`id`) Reading it now Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/#findComment-1169230 Share on other sites More sharing options...
requinix Posted February 3, 2011 Share Posted February 3, 2011 1. A TINYINT auto_increment column? A TEXT date? No no no. At the very least, change the table to use a DATE or DATETIME for the `date` field. Quote Link to comment https://forums.phpfreaks.com/topic/226533-query-help/#findComment-1169256 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.