PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 15th, 2013, 11:43 AM
paulocore paulocore is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 16 paulocore User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #2  
Old January 15th, 2013, 11:51 AM
Jyncka's Avatar
Jyncka Jyncka is offline
We're trapped inside a game!
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2008
Location: Maryland
Posts: 299 Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)Jyncka User rank is Lieutenant General (80000 - 90000 Reputation Level)  Folding Points: 37258 Folding Title: Starter FolderFolding Points: 37258 Folding Title: Starter Folder
Time spent in forums: 5 Days 9 h 30 m 29 sec
Reputation Power: 902
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.

Reply With Quote
  #3  
Old January 15th, 2013, 08:54 PM
portcitysoftwar portcitysoftwar is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2012
Posts: 163 portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level)portcitysoftwar User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 13 h 18 m 54 sec
Reputation Power: 17
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.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Limit logs 2

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap