I have a database with about 1,000 names in it, I want to track if they were sent a welcome email so I have set up a new column that will be just "y" for yes and "n" for no.
How would I go about inserting the "y" into the new database column for those 1,000 accounts?
Populating a new field in an established database
Moderator: General Moderators
-
SawkenDotCom
- Forum Newbie
- Posts: 5
- Joined: Tue Feb 22, 2005 1:22 pm
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Not sure if you can do this but
"INSERT INTO `yourtablename` (mailrecvd) VALUES ('y')"
Otherwise... if you have a primary key with some sort of auto-increment just loop over each row and insert it like this
"INSERT INTO `yourtablename` (mailrecvd) VALUES ('y')"
Otherwise... if you have a primary key with some sort of auto-increment just loop over each row and insert it like this
Code: Select all
$query = "SELECT * FROM `tablename`";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
for ($i=0; $i<$numrows; $i++) {
$id = mysql_result($result, $i, 'id');
$insert_query = "INSERT INTO `tablename` (`mailrecvd`) VALUES ('y') WHERE id=`$id`";
$insert_result = mysql_query($insert_query);
}-
SawkenDotCom
- Forum Newbie
- Posts: 5
- Joined: Tue Feb 22, 2005 1:22 pm
That's the point, it's just that I already have over a thousand accounts in the table and for the life of me couldn't figure out the best way to make it so that the accounts that already recieved the welcome email were checked by the cron job.Burrito wrote:why not just include another field on the table that has the user information and then update that row when the mail has been sent?
-
SawkenDotCom
- Forum Newbie
- Posts: 5
- Joined: Tue Feb 22, 2005 1:22 pm
Thanks! I will try it later tonight.d11wtq wrote:Not sure if you can do this but
"INSERT INTO `yourtablename` (mailrecvd) VALUES ('y')"![]()
Otherwise... if you have a primary key with some sort of auto-increment just loop over each row and insert it like this
Code: Select all
$query = "SELECT * FROM `tablename`"; $result = mysql_query($query); $numrows = mysql_num_rows($result); for ($i=0; $i<$numrows; $i++) { $id = mysql_result($result, $i, 'id'); $insert_query = "INSERT INTO `tablename` (`mailrecvd`) VALUES ('y') WHERE id=`$id`"; $insert_result = mysql_query($insert_query); }
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Grrrd11wtq wrote:Not sure if you can do this but
"INSERT INTO `yourtablename` (mailrecvd) VALUES ('y')"![]()
Otherwise... if you have a primary key with some sort of auto-increment just loop over each row and insert it like this
Code: Select all
$query = "SELECT * FROM `tablename`"; $result = mysql_query($query); $numrows = mysql_num_rows($result); for ($i=0; $i<$numrows; $i++) { $id = mysql_result($result, $i, 'id'); $insert_query = "INSERT INTO `tablename` (`mailrecvd`) VALUES ('y') WHERE id=`$id`"; $insert_result = mysql_query($insert_query); }
*cough* UPDATE is what you need yes.
*Banging head on wall again*
Nite then guys
zzzzzzzzzzzzzzzzzzzzzz.........zzz...........
LOL