Solarpitch Posted June 30, 2007 Share Posted June 30, 2007 Hey Guys, I currently have 2 tables in my database. One called "members" and another called "phpbb_users" (which is the user's table in my forum) Basically I want to get all the results from my members tables and then automatically insert the values into the phpbb_users table. I have the following code below which I am trying but doesn't work. Can anyone offer a little support on this? $mysql_connect = new mysqli("localhost", "xxxxx", "xxxxx"); $mysql_connect->select_db('xxxxx'); $query1 = ("SELECT * FROM members"); $result1= mysqli_query($mysql_connect, $query1); while($row = $result1->fetch_assoc()) { ****** This code just returns the next user id value in phpbb_users. $query = ("SELECT MAX(user_id) `user_id` FROM `phpbb_users`"); $result = mysqli_query($mysql_connect, $query); $row = $result->fetch_assoc(); $get_val = $row['user_id']; $get_val++; ****** $sql = "INSERT INTO phpbb_users (user_id, username, user_password, user_regdate, user_email) VALUES ('$get_val',". $row['username'] .",". $row['user_password'] .",".time().",". $row['email'] .")"; mysqli_query($mysql_connect, $sql); } Link to comment https://forums.phpfreaks.com/topic/57887-logical-database-query-question/ Share on other sites More sharing options...
Barand Posted June 30, 2007 Share Posted June 30, 2007 if the user_id column in phpbb_users table is defined as auto_increment, you can INSERT INTO phpbb_users (username, user_password, user_regdate, user_email) SELECT username, user_password, NOW(), email FROM members Link to comment https://forums.phpfreaks.com/topic/57887-logical-database-query-question/#findComment-286838 Share on other sites More sharing options...
Solarpitch Posted June 30, 2007 Author Share Posted June 30, 2007 See I have all that working fine. Its just now that I have created a forum, I want to copy all my existing users from my "members" table and insert them into the "phpbb_users" table rather thank having to do this for every single record in the database I want to do it in one go. Link to comment https://forums.phpfreaks.com/topic/57887-logical-database-query-question/#findComment-286839 Share on other sites More sharing options...
Barand Posted June 30, 2007 Share Posted June 30, 2007 I just gave you a query to do exactly that. Link to comment https://forums.phpfreaks.com/topic/57887-logical-database-query-question/#findComment-286840 Share on other sites More sharing options...
Solarpitch Posted June 30, 2007 Author Share Posted June 30, 2007 Sorry, I read your code wrong! I'll give that a try Link to comment https://forums.phpfreaks.com/topic/57887-logical-database-query-question/#findComment-286844 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.