Raised This Month: $ Target: $400
 0% 

SQL - Get multiple data from a single query


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 01-24-2011 , 23:53   SQL - Get multiple data from a single query
Reply With Quote #1

I've been struggling with getting this to work, as I'm running multiple queries to get different columns of data from a database. How can I get multiples items using a single query ("SELECT * FROM"), or is this not possible?
noodleboy347 is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 01-25-2011 , 02:54   Re: SQL - Get multiple data from a single query
Reply With Quote #2

PHP Code:
while(SQL_FetchRow(hQuery)) // rows
{
    
SQL_FetchString(hQuery0sBuffersizeof(sBuffer));
    
SQL_FetchString(hQuery1sBuffersizeof(sBuffer));
    
// columns...

__________________
Leonardo is offline
Monkeys
Veteran Member
Join Date: Jan 2010
Old 01-25-2011 , 06:04   Re: SQL - Get multiple data from a single query
Reply With Quote #3

I would like to suggest not using SELECT * though, but to declare every column you're using, even if you're using them all.
Because SM reads column by number, meaning you need to know their order. * uses the order of the table, but you don't know what that is from looking at the code.
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
Monkeys is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-25-2011 , 07:31   Re: SQL - Get multiple data from a single query
Reply With Quote #4

Or use SMLIB, it has some functions for reading data by column names:

http://forums.alliedmods.net/showthr...93#post1398793

Code:
stock SQL_FetchIntByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock bool:SQL_FetchBoolByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock Float:SQL_FetchFloatByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock SQL_FetchStringByName(Handle:query,  String:fieldName[],  String:buffer[],  maxlength,  &DBResult:result=DBVal_Error); 
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
Leonardo
Veteran Member
Join Date: Feb 2010
Location: 90's
Old 01-25-2011 , 08:53   Re: SQL - Get multiple data from a single query
Reply With Quote #5

looks like advertisement
__________________
Leonardo is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 01-25-2011 , 09:25   Re: SQL - Get multiple data from a single query
Reply With Quote #6

It's 266 stocks! Sure I'll be popping in almost every thread from this time.
__________________
FaTony is offline
berni
SourceMod Plugin Approver
Join Date: May 2007
Location: Austria
Old 01-25-2011 , 10:20   Re: SQL - Get multiple data from a single query
Reply With Quote #7

Quote:
Originally Posted by Leonardo View Post
looks like advertisement
I participate in this thread, what I can't say from you, when it is useful
I don't see why I shouldn't tell when it is exactly that what is needed.

/me smiles at your sig
__________________
Why reinvent the wheel ? Download smlib with over 350 useful functions.

When people ask me "Plz" just because it's shorter than "Please" I feel perfectly justified to answer "No" because it's shorter than "Yes"
powered by Core i7 3770k | 32GB DDR3 1886Mhz | 2x Vertex4 SSD Raid0
berni is offline
noodleboy347
AlliedModders Donor
Join Date: Mar 2009
Old 01-26-2011 , 00:47   Re: SQL - Get multiple data from a single query
Reply With Quote #8

Quote:
Originally Posted by berni View Post
Or use SMLIB, it has some functions for reading data by column names:

http://forums.alliedmods.net/showthr...93#post1398793

Code:
stock SQL_FetchIntByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock bool:SQL_FetchBoolByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock Float:SQL_FetchFloatByName(Handle:query,  String:fieldName[],  &DBResult:result=DBVal_Error);
stock SQL_FetchStringByName(Handle:query,  String:fieldName[],  String:buffer[],  maxlength,  &DBResult:result=DBVal_Error); 
This is great, thanks
noodleboy347 is offline
Reply



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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 09:52.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode