473,657 Members | 2,496 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

removing linebreaks when inserting to mySQL?

I'm using a textarea to insert some notes into a database.
It's inserting the complete result into the mySQL table including the
linebreaks...an d not as a visible symbol but an actual linebreak. If I
select the fireld in mySQL at a command prompt, the results take an
inordinate amount of space from all the linebreaks.

I tried nl2br() before it goes into the INSERT, but all that does is ADD <br
/> to the data but it still have linebreaks in the field.

Is there some way to replace linebreaks with something else than the break
itself so I can save database space?

Thanks!
Jul 17 '05 #1
5 2263
In article <ekWcc.207172$1 p.2334423@attbi _s54>,
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote:
Is there some way to replace linebreaks with something else than the break
itself so I can save database space?


You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?

JP

--
Sorry, <de*****@cauce. org> is een "spam trap".
E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.
Jul 17 '05 #2
"Jan Pieter Kunst" <de*****@cauce. org> wrote in message
news:de******** *************** ****@news1.news .xs4all.nl...
In article <ekWcc.207172$1 p.2334423@attbi _s54>,
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote:
Is there some way to replace linebreaks with something else than the break itself so I can save database space?
You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?


Isn't is taking up more space with the line breaks?
in mySQL if I type:select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+
?
Thanks!
Jul 17 '05 #3
On Wed, 07 Apr 2004 17:32:53 +0000, Mechphisto wrote:
"Jan Pieter Kunst" <de*****@cauce. org> wrote in message
news:de******** *************** ****@news1.news .xs4all.nl...
In article <ekWcc.207172$1 p.2334423@attbi _s54>,
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote:
> Is there some way to replace linebreaks with something else than the break > itself so I can save database space?


You can of course do a str_replace to replace the linebreaks with
another character, but the data would take up just as much space as
before, so I'm not sure what the use would be?


Isn't is taking up more space with the line breaks?
in mySQL if I type:
select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+
?
Thanks!


Can try addslashes().. which would then convert '\n' to '\\n' when the
insertion takes place, thus leaving you with '\n' in the actual DB field.
HTH =)

Regards,

Ian

--
Ian.H
digiServ Network
London, UK
http://digiserv.net/

Jul 17 '05 #4
In article <9XWcc.212128$C b.1820685@attbi _s51>,
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote:
Isn't is taking up more space with the line breaks?
in mySQL if I type:
select notes from table where id='#';

I get back:
+---------------------------------------------------------------------------
+
| First line
|
|Next line which may be longer.
|
|Another line that could be shorter but would take up as much room.
|
|So there appears to be a lot of empty space.
|
+---------------------------------------------------------------------------
+
Wouldn't it be better to have it more like:
+---------------------------------------------------------------------------
------+
| First line \n Next line which may be longer. \n |Another line that could
be shorter |
| but would take up as much room. \n So there appears to be a lot of empty
space.|
+---------------------------------------------------------------------------
------+


Well, the first version takes up more visual space, but the second one
takes up more space in the database (one linebreak character vs. four
characters: space backslash n space).

It's up to you to decide what you want to do. Personally, I would just
leave the linebreaks as entered, and perhaps do a nl2br if I want to
show the text on a webpage.

JP

--
Sorry, <de*****@cauce. org> is een "spam trap".
E-mail adres is <jpk"at"akamail .com>, waarbij "at" = @.
Jul 17 '05 #5
"Jan Pieter Kunst" <de*****@cauce. org> wrote in message
news:de******** *************** ****@news1.news .xs4all.nl...
In article <9XWcc.212128$C b.1820685@attbi _s51>,
"Mechphisto " <li**@REEMOVEme chphisto.net> wrote:
Isn't is taking up more space with the line breaks?
Well, the first version takes up more visual space, but the second one
takes up more space in the database (one linebreak character vs. four
characters: space backslash n space).


Visual only? All that space after a linebreak isn't actually IN the
database?
If that's the case, then I have no problem leaving as is. I was just afraid
that what I see is actually what's in the DB.
Thanks! =)
Liam
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
2618
by: Raqueeb Hassan | last post by:
Hello There! Have you guys tried inserting variables in mySQL tables? Do I have to use 'quote' as we had been doing to insert strings? mysql> INSERT INTO occurrence (word_id,page_id) VALUES ($word_id,$page_id); ERROR 1054: Unknown column '$word_id' in 'field list'
7
1747
by: Adam Honek | last post by:
Is there a direct way to remove one entry from a one dimensional array? I keep looking but either my eyes are funny or it isn't there. Must we really create a temp array and copy all but 1 of the entries over to delete one entry? All I want to do is remove an entry at a specified index and then have the ubound(array) go down -1.
2
4154
by: kokul_k | last post by:
Hi.. I'm facing a problem during inserting records in Mysql database. My table consists of 9 fields. When i try to insert 1000 records to this table using for loop it takes a lot of time.. nearly 5 mins. How can i reduce this time?? Can u plz help me to reduce this insertion time... Thanks in advance Kokul
2
1904
by: peter | last post by:
I have a xslt that writes a txt file from xml. Xml file is generated by a user input on a webpage and some nodes have linebreaks which corrupts my output. is there a way to generally set that xslt should ignore linebreaks or a way to use <xsl:value-of select="$VALUE"/and clear $VALUE of linebreaks or replace them with spaces?? Thanks alot! Best regards, Peter.
14
2887
by: Ben | last post by:
I don't know whether anyone can help, but I have an odd problem. I have a PSP (Spyce) script that makes many calls to populate a database. They all work without any problem except for one statement. I first connect to the database... self.con = MySQLdb.connect(user=username, passwd =password) self.cursor = self.con.cursor() self.cursor.execute("SET max_error_count=0")
5
1216
by: rweth | last post by:
I am using nntplib to download archived xml messages from our internal newsgroup. This is working fine except the download of files to the connected server, has extra embedded lines in them (all over the place), from the s.body(id,afile) # body method Is there any way to employ this library to strip out these extra line breaks? I know this may seem trivial but they cause serious issues when I try and employ the subsequent downloaded...
0
1713
by: Edwin.Madari | last post by:
-----Original Message----- statement prepared first and executed many times with exectemany - db API http://www.python.org/dev/peps/pep-0249/ inline statemets can be exeucuted only. hope that helps Edwin
6
1891
by: Bunty | last post by:
I want to insert values in the database.If i insert values one by one then it works till 4 or 5 fields then after it gives error.In my database there are more than 20 field.Pls help me.
0
8743
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8522
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8622
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7355
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1736
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.