View Full Version : SQL to check data
How to check the range of data to display information.
Database
Thelowestscore Thehighestscore Information
100 200 good
99 80 medium
If the player scores between 100 and 200, display good.
claudiuhks
02-16-2012, 05:23
Sorry, I didn't understand. Give us more informations.
Sorry, I didn't understand. Give us more informations.
99408
Sql()
{
decl String:query[1024];
Format(query, sizeof(query), "SELECT thelowestscore, thehighestscore, info FROM ipdata");
SQL_TQuery(Database, GetIpDB, query);
return false;
}
public GetIpDB( Handle:owner, Handle:hndl, const String:error[], any:data)
{
new thelowestscore, thehighestscor, info;
while (SQL_FetchRow(hndl))
{
thelowestscore = SQL_FetchInt(hndl, 0);
thehighestscor = SQL_FetchInt(hndl, 1);
info = SQL_FetchInt(hndl, 2);
}
if(num>=thelowestscore && num<=thehighestscor)
{
PrintToChatAll("\x04:\x05%s", info);
}
}
if I understand you want to sort players by score/points if so you can use ORDER BY or if you want to check a range of something you can do WHERE x>100 AND x<200
mcpan313
02-17-2012, 04:01
GetIPDB(range)
{
decl String:sQuery[96];
Format(sQuery, sizeof(sQuery), "SELECT * FROM `ipdata` WHERE `thelowestscore` <= %d AND %d <= `thehighestscore`;", range, range);
new Handle:hResult = SQL_Query(g_hDB, sQuery);
if (hResult != INVALID_HANDLE)
{
while (SQL_FetchRow(hResult))
{
new field;
SQL_FieldNameToNum(hResult, "info", field);
SQL_FetchString(hResult, field, sQuery, sizeof(sQuery));
PrintToChatAll("\x04[INFO]:\x05%s", sQuery);
}
CloseHandle(hResult);
}
}
GetIPDB(range)
{
decl String:sQuery[96];
Format(sQuery, sizeof(sQuery), "SELECT * FROM `ipdata` WHERE `thelowestscore` <= %d AND %d <= `thehighestscore`;", range, range);
new Handle:hResult = SQL_Query(g_hDB, sQuery);
if (hResult != INVALID_HANDLE)
{
while (SQL_FetchRow(hResult))
{
new field;
SQL_FieldNameToNum(hResult, "info", field);
SQL_FetchString(hResult, field, sQuery, sizeof(sQuery));
PrintToChatAll("\x04[INFO]:\x05%s", sQuery);
}
CloseHandle(hResult);
}
}
99452
how can I fix this error.
[INFO]:?? ????
Despirator
02-17-2012, 08:20
you have to change database encoding
and you should use SQL_TQuery rather than SQL_Query as it lags the server while proccessing the query
you have to change database encoding
and you should use SQL_TQuery rather than SQL_Query as it lags the server while proccessing the query
use SQL_TQuery
display :
// : error 035: argument type mismatch (argument 2)
vBulletin® v3.8.7, Copyright ©2000-2024, vBulletin Solutions, Inc.