SQL Query Problems

I am having problem with the following query:

 steamID = ply:GetNWString("SteamID")
 totalTags = sql.QueryValue("SELECT count(tags) FROM player_stats WHERE unique_id = '"..steamID.."'")
 totalDeaths = sql.QueryValue("SELECT count(deaths) FROM player_stats WHERE unique_id = '"..steamID.."'")

It is just returning the value “False” is what shows up in my label…

I have also tried:

 steamID = ply:GetNWString("SteamID")
 totalTags = sql.QueryValue("SELECT tags FROM player_stats WHERE unique_id = '"..steamID.."'")
 totalDeaths = sql.QueryValue("SELECT deaths FROM player_stats WHERE unique_id = '"..steamID.."'")

They both return “false” and I have no idea why!

Is there actually a row with that steamid? Or is there a column called unique_id?


function TableCheck()
 if (sql.TableExists("player_stats")) then
  Msg("*****Table Already Exists - No Need To Create It Again!*****
")
 else
  if (!sql.TableExists("player_stats")) then
   Msg("*****Table Not Found - Creating a New Table Now!*****
")
   query = "CREATE TABLE player_stats ( unique_id varchar(255), tags int, deaths int )"
   result = sql.Query(query)
  end
 end
end

Hum… Did you do this?
[lua]
function SetNWSteamID( ply )

ply:SetNWString("SteamID", ply:SteamID())

end
hook.Add(“PlayerInitialSpawn”, “SetNWSteamID”, SetNWSteamID)
[/lua]

Yep

I still have yet to find a solution to this problem.

did you make something like :
[lua]sql.Query( “INSERT INTO player_stats (‘unique_id’, ‘tags’, ‘death’, )VALUES (’”…SID…"’, ‘0’, ‘0’)" )[/lua] at the playerinitial spawn ?

I sure did.

**[Player.SteamID

http://wiki.garrysmod.com/favicon.ico](http://wiki.garrysmod.com/?title=Player.SteamID)** is shared now. No need for the SetNWString.

Well thats very useful. Haha but I still can’t seem to find a solution to this little problem…

Well just glancing over the thread you talk about using the sql query for a label. If you are setting the sql values serverside you won’t be able to access them clientside.

I put a section to call these

[lua]steamID = ply:GetNWString(“SteamID”)
totalTags = sql.QueryValue(“SELECT count(tags) FROM player_stats WHERE unique_id = '”…steamID…"’")
totalDeaths = sql.QueryValue(“SELECT count(deaths) FROM player_stats WHERE unique_id = '”…steamID…"’")[/lua]

in cl_init.lua
shouldn’t that pull the values?

Not if you are setting them serverside, aka init.lua.

Hmmm… well how would I go about pulling these stats onto a form on the clientside?

Bump

Usermesasges.

You… are… dumb…

No he’s not. You can use usermessages to send that data to the client (after querying the server’s sqlite database), which can ask for it with a console command.