PHP + MySQL -> Limiting to 1 Result

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
NoX Monk
Forum Newbie
Posts: 1
Joined: Sun Jul 01, 2007 9:48 am

PHP + MySQL -> Limiting to 1 Result

Post by NoX Monk »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


[b][u]Modder Info:[/u][/b] I am currently very, very new to PHP and MySQL.  I've administered an application that uses both of these elements plus XHTML for about the past year.  The application is a widely used one in the MMORPG world called [url=http://www.eqdkp.com]EQDKP[/url].  Due to recent expressions of desired enhancements, and my personal desire to learn something new, I decided to try and modify first, and develop and enhance second.

[b][u]Info:[/u][/b] I am currently trying to display 1 record, instead of displaying all records inside this application on one of the pages.  I have the query here:

Code: Select all

$sql = 'SELECT i.item_id, i.item_name, i.item_buyer, i.item_date, i.raid_id, i.item_value, r.raid_name, m.member_class_id, c.class_name AS 											classr_name, m.member_name
            FROM ' . ITEMS_TABLE . ' i, ' . RAIDS_TABLE . ' r, ' . CLASS_TABLE . ' c, ' . MEMBERS_TABLE . ' m
            WHERE i.item_buyer = m.member_name
            AND m.member_class_id = c.class_id
            AND r.raid_id=i.raid_id
			AND i.item_name = CONVERT(_utf8 \'Helm of the Vanquished Defender\' USING latin1)
            ORDER BY '.$current_order['sql']. '
            LIMIT '.$start.','.$user->data['user_ilimit'];
Goal/Question: I would like for this to display only the first result the query receives. So far I've searched and tried adding the

Code: Select all

TOP 1
and

Code: Select all

ROWCOUNT
functions to the query, but it only nets me a blank white page after that. I have considered the fact that since I do not have a deep knowledge of the application; that merely using one of those functions or a 'LIMIT 1' statement may not be possible, in which case I would have to write and display my own query. I'm hoping this can be resolved through modifying this query. Any information you can lend would be appreciated.

Thanks!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

LIMIT 1 or LIMIT x, 1 is what you're looking for.
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Post by Zoxive »

You already are telling mysql to limit your results with $start, and $user->data['user_limit']

So either change those variables, or remove them.
Post Reply