Quote:
Originally Posted by krekers
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.
__________________