samuel_lopez Posted October 28, 2015 Share Posted October 28, 2015 (edited) THis is my current code but it's not working $sqlgetstud = $mysqli->query("Select stud_id, namestud from students"); while($retvalran = mysqli_fetch_array($sqlgetstud )) { $a = $retvalran['sstud_id']; $b = $retvalran['namestud']; foreach ($a as $key => $b) { $sql = $mysqli->query("Insert into newstudent(stud_id,Name) VALUES('".$key."','".$b."'); } } Edited October 28, 2015 by samuel_lopez Quote Link to comment Share on other sites More sharing options...
0x00 Posted October 28, 2015 Share Posted October 28, 2015 You are looping over this variable you have just fetched from the database: $a = $retvalran['sstud_id']; Its only going to be a simple datatype, since its named *id, I'm guessing its an integer... and not an associative array Quote Link to comment Share on other sites More sharing options...
Barand Posted October 28, 2015 Share Posted October 28, 2015 Also, $retvalran['sstud_id'] does not exist - the column name is 'stud_id' and not 'sstud_id'. If you are just transferring data from students table to newstudent table then all you need is a single query INSERT INTO newstudent (stud_id, name) SELECT stud_id, namestud FROM students Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.