change e-mails in db
Moderator: General Moderators
change e-mails in db
hi all
I've got db of users e-mail addresses. What I have to do is change part of privider name in these e-mail addresses.
Eg.
name. surname@pu.provider.hr
change to
name.surname@pu.t-com.hr
all that should be changed is name of provider, becouse provider has joined to t-com group, and all e-mail addresses have changed.
regards ddragas
I've got db of users e-mail addresses. What I have to do is change part of privider name in these e-mail addresses.
Eg.
name. surname@pu.provider.hr
change to
name.surname@pu.t-com.hr
all that should be changed is name of provider, becouse provider has joined to t-com group, and all e-mail addresses have changed.
regards ddragas
-
jabbaonthedais
- Forum Contributor
- Posts: 127
- Joined: Wed Aug 18, 2004 12:08 pm
So the e-mail addresses in your database are like:
email1@pu.provider.hr
email2@pu.provider.hr
etc.?
Or do they already have a "something".email1@pu.provider.hr ?
email1@pu.provider.hr
email2@pu.provider.hr
etc.?
Or do they already have a "something".email1@pu.provider.hr ?
they already have a "something", and it is usualy name. It also could be just "something@pu.provider.hr".
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
//assuming you are looping through the users
while ($row = mysql_fetch_assoc($result))
{
$email = $row['name'] . $row['surname'] .'@pu.t-com.hr';
//assuming you have an id, name and surname column
$sql = "UPDATE `users` SET `email`='$email' WHERE `id`='".$row['id']."'";
$update = mysql_query($sql) or die(mysql_error());
mysql_free_result($update);
}Thank you for quick reply.
This could work, but what with these e-mails where first part of email is not "name.surname". As I've metion it abowe - It also could be just "something@pu.provider.hr".
"something" can be anything.
can it be done somehow with %LIKE% in SQL
This could work, but what with these e-mails where first part of email is not "name.surname". As I've metion it abowe - It also could be just "something@pu.provider.hr".
"something" can be anything.
can it be done somehow with %LIKE% in SQL
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
Code: Select all
<?php
//assuming you are looping through the users
while ($row = mysql_fetch_assoc($result))
{
$prevemail = explode('@',$row['email'];
if ($prevemail[1] == 'provider.hr')
{
$email = $row['name'] . $row['surname'] . '@pu.t-com.hr ';
//assuming you have an id, name and surname column
$sql = "UPDATE `users` SET `email`='$email' WHERE `id`='".$row['id']."'";
$update = mysql_query($sql) or die(mysql_error());
mysql_free_result($update);
}
}
?>
Last edited by John Cartwright on Mon Oct 11, 2004 3:47 pm, edited 2 times in total.
- John Cartwright
- Site Admin
- Posts: 11470
- Joined: Tue Dec 23, 2003 2:10 am
- Location: Toronto
- Contact:
- twigletmac
- Her Royal Site Adminness
- Posts: 5371
- Joined: Tue Apr 23, 2002 2:21 am
- Location: Essex, UK
You could just use MySQL's REPLACE() function and LIKE:
Mac
Code: Select all
UPDATE table set email = REPLACE(email, 'provider.hr', 't-com.hr') WHERE email LIKE ='%provider.hr'