Ok I got the function to read the rows. However there was a problem. Here's the code, but it displays everyones stats within the database rather then just the person making the query.
Code:
public read_user_stats(id){
// sql connect
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx("[sqlStats] SQL Connection Failed")
else{
// run a query
result = dbi_query(g_dbc,"SELECT * FROM statstable WHERE kills AND headshots")
new Data_kills
new Data_HS
// notice here that we run the dbi_nextrow first - one of the main reasons I don't like DBI.
// you MUST do this, it doesn't start at the first row
while(dbi_nextrow(result))
{
// get the row
// note that we could also use dbi_result(Result,"you")
Data_kills = dbi_result(result,"kills")
Data_HS = dbi_result(result,"headshots")
// tell the server console we have found data
client_print(id,print_chat, "* %d kills, %d Headshots.", Data_kills, Data_HS);
dbi_close(g_dbc)
}
}
}
So... I tried this.... thinking that only the the rows that match the persons authid would be returned. This returns "0" though..
Code:
ublic read_user_stats(id){
new g_Data_kills[33]
new g_Data_HS[33]
new g_authid[32]
get_user_authid(id,g_authid,31)
// sql connect
g_dbc = dbi_connect(g_host,g_user,g_pass,g_dbname,g_error,MAX_NAME_LENGTH)
if (g_dbc == SQL_FAILED)
log_amx("[sqlStats] SQL Connection Failed")
else{
// run a query
result = dbi_query(g_dbc,"SELECT * FROM statstable WHERE authid = '%s'",g_authid)
if (result == RESULT_FAILED) {
log_amx("[MySQL Test] MySQL Query Failed!!") // If it failed, we can't get the data.
return PLUGIN_CONTINUE // Query failed! Sorry :P
}
else if (result == RESULT_NONE) { // If it didn't fail, but they don't have an entry,
g_Data_kills[id] = 0 // This will create a new entry in the database
g_Data_HS[id] = 0
}
else {
dbi_nextrow(result) // This retrieves data from your query.
g_Data_kills[id] = dbi_result(result,"kills")
g_Data_HS[id] = dbi_result(result, "headshots")
}
client_print(id,print_chat, "* %d kills, %d Headshots.", g_Data_kills, g_Data_HS);
dbi_free_result(result) // You MUST free the result! Or else memory leaks will ensue!!!
dbi_close(g_dbc)
}
return PLUGIN_HANDLED;
}
any ideas?
__________________