• Mysqloo for each record to array
    4 replies, posted
Hi I have been trying to make a loop for mysqloo so it would output each record in the database to an array. It´s basically "groupid", "groupname" and "groupdesc" i want to put in an array. Heres the table information: Table name: gm_activitylog_groups id INT(11) NOT NULL AUTO_INCREMENT, groupname VARCHAR(15) DEFAULT NULL, groupdesc VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id) Heres my code so far: [lua] local arrayBuilderQuery = database:query("SELECT * FROM gm_activitylog_groups") local data = arrayBuilderQuery:getData() if arrayBuilderQuery:getData() then activitylog.groups = {} // Loop for each record in table for k, v in pairs( ? ) do // <--- and this is where im at right now and need some help... // Here we want to build an array with the data from the table // So heres how we want to build our array first the id, groupname, groupdesc. activitylog.groups[1] = data[1] end else print("Error: No groups found!") end [/lua] /tb
MySQL OO returns using string keys, instead of number keys. Try using PrintTable to see the structure. activitylog.groups[1] = data[k].id, if I recall correctly. I'll have to double check later but that should get you started.
Hey! Since i´m in the middle of starting a new gamemode it wouldnt really matter if I use tmysql or mysqloo. So if I could do it with tmysql how would that go? /tb
Use mysqloo, I've heard that tmysql can cause lag when called. I have had no problems with mysqloo.
You're not giving your query any time to run.
Sorry, you need to Log In to post a reply to this thread.