Hey how would I be able to duplicate my only auto increment key to another key, basically I want my (' id ') to display the same information on my (' user_id '), here is the code:
CREATE TABLE IF NOT EXISTS `".$db_table_prefix."users` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(10) NOT NULL, `user_name` varchar(50) NOT NULL, `username` varchar(50) NOT NULL, PRIMARY KEY (`id`), KEY `user_id` (`id`)
How would I be able to input the same information from my id to my user_id?
preguntado el 09 de septiembre de 13 a las 23:09
Not sure what you mean but if you want to have the same value repeted two times in the same record It's pointless and redundant.
You can use the SQL aliases to achive what you want:
SELECT id as user_id FROM ...
If you really need to sync up the two field of your table you can do:
UPDATE table SET user_id = id WHERE user_id != id
Not sure why you would want to do this, but if you want to duplicate the information después de an
INSERT you would need to fetch the new ID and then perform an
// get the newly inserted ID $new_id = $db->insert_id; // perform the update on the table $db->query("UPDATE users SET user_id=".$db->escape($new_id)." WHERE id=".$db->escape($new_id));
Also, in your table definition the fields don't match: