#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    utr
    Posts
    9
    Rep Power
    0
    i use a simple loop to get the news out of a database. But my problem is that i want the latest news on top and not on the bottom. I tried using DESC but then i get a error:
    'Warning: Supplied argument is not a valid MySQL result resource in D:httpdHTDOCSplopnews.php4 on line 8'
    where lin 8 is the line with:

    $rowcount = mysql_numrows($results);

    can some1 help me?
    code:
    $db = "plop";
    mysql_connect("localhost","root");
    $sql = "SELECT * FROM nieuws";
    $results = mysql_db_query($db,$sql);
    $rowcount = mysql_numrows($results);

    for($i=0; $i < $rowcount; $i++){
    echo "<b><u>" . mysql_result($results,$i,"title") . "</u></b><br>";
    echo mysql_result($results,$i,"news") . "<br>";
    echo "<br>";
    }
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    You can't use the DESC keyword if you don't use an ORDER BY clause.

    You can't assume that the oldest record comes first just because it was inserted first. You need to add some sort of date/time field and order by that.
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    utr
    Posts
    9
    Rep Power
    0
    i tried with a :

    $sql = "SELECT * FROM nieuws ORDER BY id DESC";

    it still gives the output in the same order, i tried ASC too, but doesnt work either.

    thx for any help!

    btw i havent used a datestamp or anything.

Similar Threads

  1. How to clear a string in a loop??
    By Gecko22 in forum ASP Programming
    Replies: 2
    Last Post: January 23rd, 2004, 01:35 PM
  2. A mixed foreach loop
    By Datamike in forum Dev Shed Lounge
    Replies: 11
    Last Post: December 17th, 2003, 08:40 PM
  3. Getting results from one loop into another loop
    By camcim in forum PHP Development
    Replies: 1
    Last Post: September 26th, 2003, 08:26 AM
  4. pointer array in while loop
    By ppp0 in forum C Programming
    Replies: 4
    Last Post: September 1st, 2003, 09:17 AM
  5. PHP: create tables w/ loop & iterate functions ?
    By dmonk in forum Beginner Programming
    Replies: 1
    Last Post: July 6th, 2003, 10:41 AM

IMN logo majestic logo threadwatch logo seochat tools logo