Jump to content

Need help With SQL


Edikosh998

Recommended Posts

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
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 by Guest
Link to comment
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?? :D:D

Now it says, "attempt to get leght of local request (number value)"

Link to comment

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...