0

Good day

What I would like to do is to alter a mysql table with data in it then add manipulated string data to that created column i.e I first add an extra column to my table then add a reverse string coded from data that had already been inserted.

I have an email field in my database so what I would actually do is to take the email address reverse string it then insert it into the newly added mysql column.

My reverse string works perfectly its just that I can't seem to add the extra column to my table, any ideas would be highly appreciated.

Here is my code

$query1="alter table Registration add column Deep text (20)";
$result1=mysql_query($query1);

//here's the query that selects the email field
$sql="select email fromRegistration";
$result2=mysql_query($sql);

While($row=mysql_fetch_array($result2))
{
$my_str=strrev($row['email_add']));

echo $my_str."<br>";

}

But the table isn't getting altered.

2
Contributors
2
Replies
14
Views
3 Years
Discussion Span
Last Post by kgizo
0

This can be done from just mysql - no php as such req'd

ALTER TABLE Registration ADD COLUMN Deep TEXT (20)

UPDATE Registration SET Deep = REVERSE(email_add)

There's no need to do this though as you're just repeating info to some extent.

You can retrieve the reverse string at any time with php (as you've done) or...

SELECT REVERSE(email_add) AS Deep FROM Registration

So in this case Deep is just a calculated field - it doesn't exist in the DB.

0

Thanks diafol it's much appreciated!!

That was pretty awesome.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.