newcaree Posted December 9, 2007 Share Posted December 9, 2007 I am very new to PHP and I was looking to get some help changing some code that is part of a script I purchased. The code produces "random" articles from the database. I would like to change the "random" to the order in which they are added to the database. Here is the code: $count = db_query_onecell("SELECT COUNT(article_id) FROM article"); $LEN = 100; function random_article($count) { global $LEN; $id = rand(1, $count); $data = db_query_onerow("SELECT * FROM article WHERE article_id = '$id'"); if($data["article_id"] != $id) { $id = rand(1, $count); $data = db_query_onerow("SELECT * FROM article WHERE article_id = '$id'"); } if(strlen($data["summary"]) > $LEN) $data["summary"] = substr($data["summary"], 0, $LEN) . "..."; return $data; } for($i = 0; $i < 6; $i++) { $data = random_article($count); $id = $data["article_id"]; $title = $data["title"]; $summary = clean($data["summary"]); $REPLACE["left1"] .= "<b><a href=\"" . get_link("article", "a", $id, 0, $title) . "\">$title</a></b><br>$summary\n<br><br>"; } Thank you for any help in advance. Quote Link to comment Share on other sites More sharing options...
PC Nerd Posted December 9, 2007 Share Posted December 9, 2007 ok change your query to: "SELECT * FROM article ORDER BY article_time DESC LIMIT 1" youll have to make sure that your article's table stores when the article was added, and youll have to chek that field name and replace "article_time" with the field name. If you have any nmore problems let us know.... Quote Link to comment 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.