Edikosh998 Posted February 28, 2012 Share Posted February 28, 2012 Hello guys, I need some help with SQL syntax. What i want is to make a function where it shows the number of rows that a column has. So I made this function rows (thePlayer,cmd) local query = executeSQLQuery("SELECT COUNT(ID) FROM vehiculos") outputChatBox("There are: "..#query..".",thePlayer) end -- RESULT : 1...(its not empty), but it doesn't show the amount of rows that it has. See ya. Link to comment
Kenix Posted February 28, 2012 Share Posted February 28, 2012 (edited) local request = executeSQLQuery( "SELECT COUNT FROM vehiculos" ) if type( request ) == 'table' and #request > 0 then for i,v in pairs( request ) do outputChatBox( "Index = '" .. tostring( i ) .. "' , Value = '" ..tostring( v ) ) end end ? Edited February 28, 2012 by Guest Link to comment
Edikosh998 Posted February 28, 2012 Author Share Posted February 28, 2012 local request = executeSQLQuery( "SELECT COUNT FROM vehiculos" ) or 0 if #request > 0 then for i,v in pairs( request ) do outputChatBox( "Index = '" .. tostring( i ) .. "' , Value = '" ..tostring( v ) ) end end ? Debugger said : 211 bad argument #1 'pairs' (got boolean, not table) That's because COUNT needs a column name. Perhaps, Im not clear with my request (my english is not so good). I want a print (outputChatBox) of the number of rows. http://www.1keydata.com/sql/sqlcount.html EDIT : You edit the answer?? Now it says, "attempt to get leght of local request (number value)" Link to comment
Kenix Posted February 28, 2012 Share Posted February 28, 2012 My bad Updated again. So if condition ( true ) then loop it. Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now