nick.a Posted February 20, 2011 Share Posted February 20, 2011 Hello, I've decided to make myself a very simple php script to write data into a DB and read it from there... So, my question is. How would I be able to make so that the page where the script is included to show only the newest 3 articles and puts the others on pages (1,2,3... etc) ? Ideas would be appreciated. A bit of scripting help would be really, really appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/228262-php-news-script-question-probably-concerning-mysql/ Share on other sites More sharing options...
QuickOldCar Posted February 20, 2011 Share Posted February 20, 2011 It's gonna be hard for anyone to give code when they don't know what you have. Here's a method I use on my site for the main page. I use a multiple mysql query and search/navigation using pagination. I don't know how you do your site at all. $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } if ($url == "http://mysite.com/") { //can also add index.php or w/e you need with OR $result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT 0,3"); } else { $result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT 0,10"); } If this doesn't help you and nobody else chimes in and walks you through I can help in a few days. I'll be too busy next few days. Quote Link to comment https://forums.phpfreaks.com/topic/228262-php-news-script-question-probably-concerning-mysql/#findComment-1177134 Share on other sites More sharing options...
QuickOldCar Posted February 20, 2011 Share Posted February 20, 2011 I tried to break this down in another way and also try to explain it. //this gets the current url $url = filter_var("http://".$_SERVER['HTTP_HOST'].$_SERVER['SCRIPT_NAME'], FILTER_SANITIZE_STRING); if (!empty($_SERVER["QUERY_STRING"])){ $query_string = filter_var($_SERVER['QUERY_STRING'], FILTER_SANITIZE_STRING); $url .= "?".$query_string; } //startrow would be used for any pagination you have to tell mysql where to start from $startrow = 0; //this sets the amount depending on what the url is if ($url == "http://mysite.com/") { //can also add index.php or w/e you need with OR $post_amount = 3; } else { $post_amount = 10; } //the partial mysql query $result = mysql_query("SELECT * FROM table ORDER BY ID DESC LIMIT $startrow,$post_amount"); Quote Link to comment https://forums.phpfreaks.com/topic/228262-php-news-script-question-probably-concerning-mysql/#findComment-1177135 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.