Sign in to follow this  
djharbi2

[Help] Database Error

Recommended Posts

Hi, I want to print the matching value but I can't 

Can you help, thank you ...

server.Lua

local vehDB = dbConnect( 'sqlite', 'vehicle.db' )
dbExec(vehDB,' CREATE TABLE IF NOT EXISTS `vehicle_base` (pAcc, vehicleID, vehicleName, vehiclePrice, vehicleStatus, vehicleHP)')

function dategetV()
local results = dbPoll(dbQuery(vehDB, "SELECT * FROM `vehicle_base` WHERE vehicleID=? AND pAcc=?",520,getAccountName(getPlayerAccount(source))), -1) 
 if results then 
            for k,v in ipairs ( results ) do 
            outputDebugString(tostring(v['vehicleHP']))
        end 
    end 
end
addEvent("dategetV", true)
addEventHandler("dategetV", getRootElement(getThisResource()), dategetV)
Edited by djharbi2

Share this post


Link to post

want to pull the vehicleHP value of the matching person

For example:
djharbi, 520, infernus, 100, good,1000 (This is a sample data)

The data I want > 1000 (vehicleHP)
 

Share this post


Link to post
3 hours ago, djharbi2 said:

want to pull the vehicleHP value of the matching person

For example:
djharbi, 520, infernus, 100, good,1000 (This is a sample data)

The data I want > 1000 (vehicleHP)
 

That's exactly what your code does. So what's your issue? Nothing prints out even if the value exists in the database?

Share this post


Link to post
1 hour ago, djharbi2 said:

yes that's exactly the problem

At line 5, use tostring(520) instead of 520.

Share this post


Link to post
2 minutes ago, djharbi2 said:

problem persists

Your code seems fine to me. Try to install DB browser to check if all the values really exist in your database.

Share this post


Link to post
19 minutes ago, djharbi2 said:

If you recreate the above code, I would be glad, you can do it

local vehDB = dbConnect("sqlite", "vehicle.db")
dbExec(vehDB, "CREATE TABLE IF NOT EXISTS vehicle_base (pAcc TEXT, vehicleID TEXT, vehicleName TEXT, vehiclePrice TEXT, vehicleStatus TEXT, vehicleHP TEXT)")

function dateGetV()
	local accName = getAccountName(getPlayerAccount(source))
	local qh = dbQuery(vehDB, "SELECT * FROM vehicle_base WHERE vehicleID=? AND pAcc=?", "520", accName)
	local result = dbPoll(qh, -1)
	if result then
		for _, row in ipairs(result) do 
			outputDebugString(row["vehicleHP"])
        end 
    end 
end
addEvent("dategetV", true)
addEventHandler("dategetV", root, dateGetV)

I'd do like this.

Edited by HassoN
  • Like 1

Share this post


Link to post

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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.