The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Databases
> MySQL Help
|
\n in field value
Discuss \n in field value in the MySQL Help forum on Dev Shed. \n in field value MySQL Help forum discussing administration, SQL syntax, and other MySQL-related topics. MySQL is an open-source relational database management system (RDBMS).
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

June 8th, 2000, 07:31 AM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Good day all,
I recently imported a text file into a database and although I specified that the lines ended with 'n', this was picked up in the last row as a value.
So now I have 8000 rows with this as a value in the last field.
In code, as I scan the rows, I say:
if(($i == 7) && (htmlspecialchars($row[$i])!="")){echo "<a href="".htmlspecialchars($row[$i]).""Click Here</a>";}
else{echo" ";}
It always shows up as a value.
This puts a link on an empty field. Looks terrible on the html page.
The source of the created html page reflects a 'newline' at this point.
Question:
How to get rid of this 'newline'('n') in the field values.
When I search for this, it always comes up with 'empty set'. I must be searching wrong??
Thanks for any help.
Jim
|

June 8th, 2000, 03:28 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Try this:
update table set problem_field=trim(trailing 'n' from problem_field);
|

June 8th, 2000, 04:52 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
Howdy,
I tried your suggestion but it did not work.
I even tried variations of the code (ie: left out the word 'trailing') but still no good.
Problem might be that as before, mysql sees an empty field.
Any other suggestions are greatly appreciated.
Thanks,
Jim
|

June 8th, 2000, 05:36 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Well, the only other suggestion I can come up with is processor intensive but if you only have to do it once....
$result=mysql_query("select id,prob_field from table"); // where id is your unique id for the table
while (list($id,$probfield)=mysql_fetch_row($result))
{
$probfield=chop($probfield);
$result2=mysql_query("update table set prob_field='$probfield' where id=$id");
}
That'll do it.
|

June 8th, 2000, 06:12 PM
|
|
Junior Member
|
|
Join Date: Jun 2000
Posts: 9
Time spent in forums: < 1 sec
Reputation Power: 0
|
|
|
howdy again,
I was going to try your code but then I got to thinking.
If the fields should be empty but they contain a 'n', then why not just update the field value to "".
So I did this:
update table set problem_field="" where problem_field = "";
and it worked. This cleared all of the problem_fields that did not contain a valid value.
Thanks for your time. I appreciate it.
Jim
|

June 8th, 2000, 07:10 PM
|
|
Apprentice Deity
|
|
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237

Time spent in forums: 4 m 8 sec
Reputation Power: 17
|
|
|
Ahhh, I misunderstood. I thought you meant the newline was included as part of the data you DID want, not the ONLY data in the field.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|