Jump to content

PHP coding for separate queries question


katarra

Recommended Posts

I had someone tell me that this will solve a problem I have, but I'm not quite sure what it means and I haven't gotten a response for a few days now. Can anyone provide an example or point me to an example? Thanks!

 

You'll need to send a separate query for each field. So if you're making an item with fields for "name", "type", "slot", and "attack power", you'll need to send four insert commands to the database.

I have a database field setup that has 3 columns: id, field, value

 

I'm wanting to use this as an item inventory repository, so that the information can be pulled when needed later in the program.

 

But, for now, I want to create the items to go into it, but each item will have multiple fields and multiple values but only a single unique id spread across a few rows. For instance, take:

 

1 weapon Sword

1 attackpower 5

1 cost 100

 

Something simple like that.

Well, first you'll have to get a unique ID since you're using it across multiple rows.  One option is to lock the table, then query for max(id) + 1.

 

Then you'll need a multi-line insert statement, or multiple single line insert statements.  In mysql, you can

INSERT INTO tablename (id, field, value) VALUES (1, 'weapon', 'sword'), (1, 'attackpower', '5'), (1, 'cost', '100');

 

Then unlock the table.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.