St2099 Posted June 16, 2010 Share Posted June 16, 2010 I'm sorry about the lack of information in the topic subject. I'll try to explain here. $var1= mysql_query("SELECT * FROM table1"); while ($var2= @mysql_fetch_array($var1)) { $id = $var2['transid']; mysql_query("INSERT INTO table 2(name, city) VALUES ('John', 'London')") or die (error25); mysql_query("DELETE FROM table1 WHERE id = '$id' ") or die(mysql_error()); } As you can see, the loop is running. If there are multiple inputs in the database(table1) with the same id, I want the loop to just run one of them, and delete the rest. But I can't get it to do this. What am I doing wrong? The result is that I get multiple Johns(example) inserted in table2. Quote Link to comment Share on other sites More sharing options...
jonsjava Posted June 16, 2010 Share Posted June 16, 2010 A breakdown of your script, as read: run a query, and return everything in the table. While parsing through the results, assign variable $id to equal column "transid". Insert into the table named `table_2` at columns name, city the values "john" and "london", respectively. Delete all occurneces from `table_1` where the `id`=$id, even though it's true name is `transid`. Ok, I think you see the issue here: <?php $var1= mysql_query("SELECT `transid` FROM table1"); while ($var2= @mysql_fetch_assoc($var1)) { $id = $var2['transid']; mysql_query("INSERT INTO table 2(name, city) VALUES ('John', 'London')") or die (error25); mysql_query("DELETE FROM table1 WHERE `transid` = '$id' ") or die(mysql_error()); } ?> 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.