[SOLVED] trim space (" ")
Moderator: General Moderators
trim space (" ")
Hi all
In database is column mail. How to trim space (" ") from begining and from end of each record.
In database is column mail. How to trim space (" ") from begining and from end of each record.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
PHP command trim - trim before you place in DB
SQL (POSTRES) trim
So if you want to trim all rows
SQL (POSTRES) trim
So if you want to trim all rows
Code: Select all
UPDATE tablename set mail=trim(mail);Thank you for quick reply, but it doesn't work
Number affected rows= 0
here is code:
Number affected rows= 0
here is code:
Code: Select all
<?php
include("../hr/con_db.php");
$sqlquery = "UPDATE mailovi SET mail = trim(mail)";
mysql_query($sqlquery) or die(mysql_error());
$broj_mailova_poslanih = mysql_affected_rows();
echo "updejtani redovi: " . $broj_mailova_poslanih;
include("../hr/disconect.php");
?>
<?php
?>- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Try a ; at the end of the SQL statement.
As I stated this works in Postgres. I am not sure what the command is for MySQL but it should be the same.
Code: Select all
$sqlquery = "UPDATE mailovi SET mail = trim(mail);";- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
There is nothing wrong with statement
It is something else
I've imported in db from "csv" file these emails, and at the end of each record, i've putted "\r\n".
I think that is couse of my problem.
Code: Select all
<?php
$sqlquery = "UPDATE mailovi SET mail = trim(mail);";
<?php
?>I've imported in db from "csv" file these emails, and at the end of each record, i've putted "\r\n".
I think that is couse of my problem.
- CoderGoblin
- DevNet Resident
- Posts: 1425
- Joined: Tue Mar 16, 2004 10:03 am
- Location: Aachen, Germany
Postgres only...
Can't find btrim in MySQL manual though and don't have any method to test it anyway...
http://dev.mysql.com/doc/mysql/en/String_functions.html
Alternative: Check before you place it in the DB to start with.
Code: Select all
UPDATE mailovi SET mail = btrim(mail,'\r\n');http://dev.mysql.com/doc/mysql/en/String_functions.html
Alternative: Check before you place it in the DB to start with.