Jump to content

Change "random"


newcaree

Recommended Posts

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.

Link to comment
Share on other sites

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....

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.