Jump to content

sql insert / delete etc


tosfera

Recommended Posts

Posted

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?

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

  • MTA Team
Posted

Can you give an example other expected generated queries? I don't quite understand your example.

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

If I helped you, please click the like button on the right ;) Thanks!

Posted

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.

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

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

Posted

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

logo-small.png?v=3 tiny-sapdfr.png

 

If you want to contact me directly concerning Advanced-Gaming, please contact me at [email protected]

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