Raised This Month: $ Target: $400
 0% 

SQL syntax


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
krekers
Junior Member
Join Date: Jul 2007
Old 07-16-2007 , 15:45   Re: SQL syntax
Reply With Quote #1

Please help me with SELECT.
I have read tutorial, but i didn't understand...
Can someone write some example ? The query:
Code:
dbi_query(dbc, "SELECT map FROM maps LIMIT 10")
I need the result print to chat. ( client_print() )


Thanks.
krekers is offline
DotNetJunkie
Senior Member
Join Date: May 2005
Location: In front of my pc
Old 07-16-2007 , 23:22   Re: SQL syntax
Reply With Quote #2

Quote:
Originally Posted by krekers View Post
Please help me with SELECT.
I have read tutorial, but i didn't understand...
Can someone write some example ? The query:
Code:
dbi_query(dbc, "SELECT map FROM maps LIMIT 10")
I need the result print to chat. ( client_print() )


Thanks.
Do you have to use DBI? SQLx is much better.

Code:
new Handle:mapQuery = SQL_PrepareQuery(g_Database, "SELECT `map` FROM `maps` LIMIT 10;");
if( !SQL_Execute(mapQuery) )
{
SQL_FreeHandle(mapQuery);
return PLUGIN_HANDLED;
}
new numMaps = SQL_NumResults(mapQuery);
new i = 0;
if( numMaps > 0 )
{
new printstr[512];
add(printstr, sizeof(printstr)-1, "We have the following maps: ");
while( SQL_MoreResults(mapQuery) )
{
new mapName[64];
SQL_ReadResult(mapQuery, 0, mapName, sizeof(mapName)-1);
if( i >= numMaps )
{
add(printstr, sizeof(printstr)-1, " and ");
}
else
{
add(printstr, sizeof(printstr)-1, ", ");
}
add(printstr, sizeof(printstr)-1, mapName);
i++;
SQL_NextRow(mapQuery);
}
client_print(id, print_chat, printstr);
}
else
{
client_print(id, print_chat, "We have no available maps.");
}
SQL_FreeHandle(mapQuery);
return PLUGIN_HANDLED;
Not tested so I don't know if it'll work without changes.
I haven't used DBI in awhile so I can't remember off the top of my head.
__________________
DotNetJunkie is offline
Send a message via ICQ to DotNetJunkie Send a message via AIM to DotNetJunkie Send a message via MSN to DotNetJunkie Send a message via Yahoo to DotNetJunkie
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 21:35.


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