I'm trying to get data from one table in a database and post it to another. The query to get the data is $sql = 'SELECT * FROM '.ADR_LBUILDINGS_TABLE.' WHERE b_owner_id = '.$owner.' $result = $db->sql_query($sql); if( !$result ) message_die(GENERAL_ERROR, 'Could not obtain buildings information', "", __LINE__, __FILE__, $sql); $buildings = $db->sql_fetchrowset($result); PHP: From this, I want one particular column, b_id. There will be a variable number of entries in this column that match the SELECT criteria, including the chance of none being there. I then want to add all these entries to another table, in the character_activated_buildings column, replacing what's currently there with all the b_id from the query, in the format #b_id# for each b_id I can't quite seem to figure out how to do it.
You want to move data from one table into another? Try insert into... insert into TABLE (VAL1) select VAL2 from TABLE2 Code (markup):
It's actually a SET command that's required. What I can't figure out is how to add all the results from the query, with the proper formatting, to the second table.
To try and make it a bit clearer, here's what I'm attempting to do. First, this query is run $sql = 'SELECT * FROM '.ADR_LBUILDINGS_TABLE.' WHERE b_owner_id = '.$owner.' $result = $db->sql_query($sql); if( !$result ) message_die(GENERAL_ERROR, 'Could not obtain buildings information', "", __LINE__, __FILE__, $sql); $buildings = $db->sql_fetchrowset($result); PHP: From this, I want all instances of b_id that match the SELECT criteria. If (no instances) {$activated='';} else if b_id list is something like 10,13,22,27 {activated = #10##13##22##27;} $sql = "UPDATE ".ADR_CHARACTERS_TABLE." SET character_activated_buildings = '$activated' WHERE character_id = ".$owner; PHP: It's the bit in the middle I'm having trouble with
You can use GROUP by command in one table and insert to other, but that is not sufficient in your case. You can try from here. http://www.plus2net.com/sql_tutorial/sql_insertsum.php Pl let me know if you are able manage with out the loop.