Thread: Limit logs 2

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Limit logs 2


    Hello.

    I'm trying to do a limit of 2 logs, but it just appear 1, does anyone know what i'm doing wrong?

    Code:
     <?php
    		 $q = mysql_query('SELECT user, rank, notes, admin, date FROM logs ORDER BY date DESC LIMIT 0,2');
    		 echo "O usuario <strong>".mysql_result($q, 0, 'user')."</strong> Foi mudado para o rank <strong>".mysql_result($q, 0, 'rank')."</strong> Com a razo de <strong>".mysql_result($q, 0, 'notes')."</strong> Pelo o administrador <strong>".mysql_result($q, 0, 'admin')."</strong> na data <strong>".mysql_result($q, 0, 'date')." </strong>.";
    		 ?>

    Thanks.
  2. #2
  3. Put a potato on it!
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2008
    Location
    Maryland
    Posts
    304
    Rep Power
    970
    I could be off, but I think mysql_result() returns only one row at a time, as many of the other mysql functions do unless they explicitly say they return multiple rows. You were already told in another threat to stay away from the mysql functions and use PDO or mysqli, so I won't repeat that advice.

    However, you don't need to specify the offset in LIMIT, just doing "LIMIT 2" will retrieve a max of two rows, by default it starts at the 0 row.

    Something to also think about, as it mentions on [PHPNET="mysql_result"]mysql_result()[/PHPNET] is to use a function that returns the entire row, rather than calling mysql_result() three times.
    Last edited by Jyncka; January 15th, 2013 at 09:33 PM.
    "Those who can make you believe absurdities can make you commit atrocities."
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    165
    Rep Power
    18
    MANY problems here. One your using a deprecated extension which will soon start yelling at you with an E_DEPRECATE error. Second the mysql_result only selects a single row from a mysql result resource.

    Mysql_result(RESOURCE,int ROW,mixed FIELD)

    While you could use this method just copy the code again and take the next row. sense you know how many rows you want before hand.

    Alternatively you could use while($row=mysql_get_asoc($q)){
    CODE
    }


    Originally Posted by paulocore
    Hello.

    I'm trying to do a limit of 2 logs, but it just appear 1, does anyone know what i'm doing wrong?

    Code:
     <?php
    		 $q = mysql_query('SELECT user, rank, notes, admin, date FROM logs ORDER BY date DESC LIMIT 0,2');
    		 echo "O usuario <strong>".mysql_result($q, 0, 'user')."</strong> Foi mudado para o rank <strong>".mysql_result($q, 0, 'rank')."</strong> Com a razo de <strong>".mysql_result($q, 0, 'notes')."</strong> Pelo o administrador <strong>".mysql_result($q, 0, 'admin')."</strong> na data <strong>".mysql_result($q, 0, 'date')." </strong>.";
    		 ?>

    Thanks.

IMN logo majestic logo threadwatch logo seochat tools logo