Jump to content

Help with loop


unplugged_web
 Share

Recommended Posts

I'm trying to get the results from one table, set a field to true, add the results to another table and repeat it 100 times. I've read about for loop and think that this is what I need to use and have written some code, but just wanted a bit of advice about it please.This is what I've got:

<?php$con = mysql_connect("hostname/server IP","username","password");if (!$con)  {  die('Could not connect: ' . mysql_error());  }for($i=100)	{	echo $i	mysql_select_db("databasename", $con);mysql_query("SELECT * FROM table_one WHERE picked = 'false' LIMIT '1'");mysql_query("UPDATE table_one SET picked = 'true'");mysql_query("INSERT INTO table_two");}mysql_close($con);?>

but I didn't know if it was right and if it would work.Thanks in advance for any advice on this. :)

Link to comment
Share on other sites

you can do like

UPDATE table_one SET picked = 'true' WHERE picked='false'

if i am not missunderstanding the problem..it should work i think..

add the results to another table and repeat it 100 times
i am not sure about this..what results are you reffering? all the result from table1 or ony updated row's result? Edited by birbal
Link to comment
Share on other sites

you can do like
UPDATE table_one SET picked = 'true' WHERE picked='false'

if i am not missunderstanding the problem..it should work i think..i am not sure about this..what results are you reffering? all the result from table1 or ony updated row's result?

ThanksIt's only the updated results that I want to add to the other table
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...