tosfera Posted October 5, 2013 Share Posted October 5, 2013 Hey, I'm walking against a few problems with some queries. I can type out the queries myself, but I'd rather give the function a table, which contains data. And out of that table, it will fill the query and insert or delete the data I gave him. Example for an insert; table = { "name" => "tosfera", "age" => "18", "gender" => "male" }; query = mysql_query ( "INSERT INTO `randomtablename` SET table[0][1]=table[0][2], table[1][1]=table[1][2], table[2][1]=table[2][2] WHERE id='1' "); but if the table changes, I'm not sure what to do. I can create a function; getDataFields, which will return all the fields and depending on that it will create different kind of inserts, but there must be an easier way. I am 100% sure there is, I just can't find it. So maybe any of you guys know the right way? I've been thinking about using an loop, but it wouldn't do the right thing. Although, if I surround the fieldnames and values with a loop, it might work... not sure. Anyone can confirm this? Link to comment
qaisjp Posted October 5, 2013 Share Posted October 5, 2013 Can you give an example other expected generated queries? I don't quite understand your example. Link to comment
xXMADEXx Posted October 6, 2013 Share Posted October 6, 2013 Your syntax is all messed up. You should read this: http://w3schools.com/sql/default.asp Link to comment
qaisjp Posted October 6, 2013 Share Posted October 6, 2013 Your syntax is all messed up. You should read this:http://w3schools.com/sql/default.asp w3schools is terrible. Only fools use it. Read http://w3fools.com. Link to comment
myonlake Posted October 6, 2013 Share Posted October 6, 2013 Your syntax is all messed up. You should read this:http://w3schools.com/sql/default.asp w3schools is terrible. Only fools use it. Read http://w3fools.com. Websites like you linked cause nothing but trouble, more than W3Schools. W3Schools is a great website to find syntaxes and stuff from. It was my source for learning HTML when I was young. You're insulting me. Link to comment
tosfera Posted October 6, 2013 Author Share Posted October 6, 2013 Its just a messy example. All I want to do is loop through a lua table and convert the values into a query. And I already got it fixed, don't bother about it. But since xXMADEXx is beind an ass and wants me ( someone who already uses databases for 2 or 3 years ) to learn how to propperly write an sql query, I won't even give away the code for the rest. Sti thanks for the repliezzz guys. Link to comment
xXMADEXx Posted October 6, 2013 Share Posted October 6, 2013 Its just a messy example. All I want to do is loop through a lua table and convert the values into a query. And I already got it fixed, don't bother about it. But since xXMADEXx is beind an ass and wants me ( someone who already uses databases for 2 or 3 years ) to learn how to propperly write an sql query, I won't even give away the code for the rest.Sti thanks for the repliezzz guys. um... No, im trying to help you learn. You'll never learn anything if people do it for you. Link to comment
tosfera Posted October 6, 2013 Author Share Posted October 6, 2013 You think, I want to learn how to write a propper SQL query? Ehmm no, never ask for a piece of code or whatever. Just want to know if the way I told, was affecting my server load etc. but oh wells. got it working. /thread Link to comment
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now