Jump to content

Display more than one result (mysql)


Cronoss

Recommended Posts

I want to display more than one result (from mysql database) in a function because in my system the player can have more than one object saved, I need  to display all the rows added. Example:

(Data base view)

row #1 = [id | car | color 3]

row#2 = [id | car | color6]

How it would look into .lua file

local thingRequest = exports.mysql:_Query("SELECT awesomething FROM thingsTable WHERE owner=?", owner)
	if (#thingRequest>0) then
		local awesomethingText1 = --awesomething[1] (row #1)
		local awesomethingText2 = --awesomething[2] (row #2)
  		if (awesomethingText1=="") then
    		return
    		else
    			awesomeEvent()
    		end
  			
  		if (awesomethingText2=="") then
    		return
    		else 
    			awesomeEvent()
    		end

 

Link to comment

But how could I display more rows then? I'm talking about something like this:

for _,column in ipairs(tableCheck) do
  	awesomethingRow1 = --------------------row 1, awesomething's first result
    awesomethingRow2 = --------------------row 2, awesomething's next result 
  

 

Link to comment

If someone could help me, this is the code where i need to "display" multiple results:

function saveInf()
    for i,vehicle in pairs(getElementsByType("vehicle")) do
    local x,y,z = getElementPosition(vehicle)
    local rx,ry,rz = getElementRotation(vehicle)
    local health = getElementHealth(vehicle)
    local engineState = getVehicleEngineState(vehicle)
        if (engineState==true) then
            engineSend = 1
        else
            engineSend = 0
        end
    local lock = isVehicleLocked(vehicle)
        if (lock==true) then
            lockSend = 1
        else 
            lockSend = 0
        end
    local plate = getVehiclePlateText(vehicle)
    local model = getElementModel(vehicle)
    local owner = getPlayerName(source)
    local sendToSQL = exports.mysql:_Query("UPDATE vehicles SET x=?, y=?, z=?, rx=?, ry=?, rz=?, health=?, engine=?, locked=?, plate=?, model=? WHERE owner=?", x,y,z,rx,ry,rz,health,engineSend,lockSend,plate,model,owner)
    if (sendToSQL) then
        iprint("1")
    end
    end
end
addEventHandler("onPlayerQuit", getRootElement(), saveInf)

I want to save the vehicles of the player but the problem is... if the player have more than one car, the system saves all the info from the last vehicle in all the rows, so when he log-in, two cars with the same info spawns in the location where the last car was used (2 cars if the player only spawned 2, if the spawned 3, 3 vehicles with the same info spawns)

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...