0

I am using a mySQL query in PHP to pull content from rows into an array. A simple for statement is then displaying this data:

    for ($i = 0; $i < ($num_rows); $i++):

        //Find Author Name
        $query = 'SELECT firstname, lastname FROM vd_users WHERE id = ?';
        $statement = $mySQL_con->prepare($query);

        //Attempt Query
        try {
            $statement->execute(array($results[0][$i]['author_id']));
        }

        //Catch Errors
        catch (PDOException $error) {
            $info = $error->getMessage();
            echo 'Sorry, we failed to load this page'; if ($_SESSION['debug'] = 1) { echo ': ' . $info; }       
        }

        //Fetch Results to Array
        $row = $statement->fetch(PDO::FETCH_ASSOC);

    endfor;

This works well. However, since new rows are added with an id++, the newer ones are displayed at the bottom, and I would like them at the top.

Is it possible to order the mySQL rows by date using a column, or will I have to look at some other way? On a hunch I tried inverting the for statement to for ($i = $row_count; $i = 0; $i--) thinking that that would do it, but nope!

I tried adding ORDER BY date to my query, but that didn't work. Note that 'date' is a column name in the database.

1
Contributor
1
Reply
8
Views
2 Years
Discussion Span
Last Post by James_43
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.