Jump to content

sql insert / delete etc


tosfera

Recommended Posts

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

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

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