Jump to content

Help [Mysql]


.:HyPeX:.

Recommended Posts

Well, i cant check if the serial was already introduced, it simply does not retrive the values..

  
function addNewTime(map,player,serial,time,name,country,date) 
local map = getMapName(map) 
outputChatBox(map) 
local query = dbQuery(Database,"SELECT * FROM "..md5(map).." WHERE serial = '"..serial.."';") 
local result = dbPoll(query,-1) 
local g_Time=nil 
local vask = nil 
if result then 
outputChatBox("rowing") 
    for _,row in ipairs(result) do 
    outputChatBox("rowing2") 
        for column,value in ipairs(row) do 
        outputChatBox(column) 
        outputChatBox(value) 
        outputChatBox(column.."  "..value) 
            if column == "serial" then 
                if value == serial then 
                vask = true 
                end 
            elseif column == "time" then 
                g_Time = value 
            end 
        end 
    end 
    if not vask then 
    local query = dbQuery(Database,"INSERT INTO "..md5(map).." (serial,name,time,country,date) VALUES ('"..serial.."','"..name.."','"..time.."','"..country.."','"..date.."');") 
    local result = dbPoll(query,-1) 
    if result then 
    outputChatBox("top added!") 
    else 
    outputChatBox("top not added!") 
    end 
  

Output:

  
Hypex-Testtopmap 
rowing 
rowing2 
rowing2 
top added! 

Table in mysql..

http://i.imgur.com/V4MAVHK.png

Thanks in advance

Link to comment

That's because "result" contains the table's values as arrays with respective index to each column name.

  
for i, row in ipairs(result) do 
    outputChatBox(row.serial) 
    outputChatBox(row.name) 
end 
  

Either way, I recommend you to use dbQuery as follows:

(Note: It is usually good practice to surround table and column names with backticks (`) in case they contain spaces or SQL keywords (and therefore cause syntax errors). This is especially true when using variables for table and column names, as potential problems may not be apparent when the script is first written. @dbQuery)

  
dbQuery(Database, "SELECT * FROM ? WHERE serial = ?", md5(map), serial) 
  

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