The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Limit logs 2
Discuss Limit logs 2 in the PHP Development forum on Dev Shed. Limit logs 2 PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 15th, 2013, 11:43 AM
|
|
Registered User
|
|
Join Date: Dec 2012
Posts: 16
Time spent in forums: 2 h 37 m 45 sec
Reputation 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 razão 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.
|

January 15th, 2013, 11:51 AM
|
 |
We're trapped inside a game!
|
|
Join Date: Jul 2008
Location: Maryland
|
|
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 mysql_result() is to use a function that returns the entire row, rather than calling mysql_result() three times.
__________________
"Those who can make you believe absurdities can make you commit atrocities."
Last edited by Jyncka : January 15th, 2013 at 09:33 PM.
|

January 15th, 2013, 08:54 PM
|
|
|
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
}
Quote: | 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 razão 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. |
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|