#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep 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"&nbsp;";}

    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
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    Try this:

    update table set problem_field=trim(trailing 'n' from problem_field);
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep 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
  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    9
    Rep 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
  10. #6
  11. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    19
    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.

Similar Threads

  1. Inserting from form to multiple tables
    By barth in forum MySQL Help
    Replies: 0
    Last Post: January 25th, 2004, 10:27 AM
  2. return value from 3 fields into 1 field
    By denali in forum MS SQL Development
    Replies: 1
    Last Post: December 19th, 2003, 08:44 AM
  3. Validating a field with multiple criteria...
    By brotherloco in forum Java Help
    Replies: 0
    Last Post: October 29th, 2003, 08:40 AM
  4. Replies: 2
    Last Post: May 12th, 2003, 04:04 AM
  5. Database design question
    By mcsimon in forum Dev Shed Lounge
    Replies: 2
    Last Post: August 5th, 2001, 01:17 AM

IMN logo majestic logo threadwatch logo seochat tools logo