Forum Articles
  Welcome back Join CF
You are here You are here: Home | Forum | A little SQL help (possibly)

You are currently viewing our boards as a guest which gives you limited access to view most of the discussions, articles and other free features. By joining our Virgin Media community you will have full access to all discussions, be able to view and post threads, communicate privately with other members (PM), respond to polls, upload your own images/photos, and access many other special features. Registration is fast, simple and absolutely free so please join our community today.


Welcome to Cable Forum
Go Back   Cable Forum > Computers & IT > General IT Discussion

A little SQL help (possibly)
Reply
 
Thread Tools
Old 19-08-2005, 20:37   #1
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
A little SQL help (possibly)

Hi Guys,

Here's the problem.

Let's say I have a field in a table which is called "txtSentence"

Now, I have a record in my table where the value of txtSentence is:

"This Is My Sentence"

However, what I actually want to display when I look for that record is:

"This
Is
My
Sentence"

I'm assuming that there is a character, or a symbol, or something (anything) that I can put between each word to force a carriage return - something like:

"This<cr>Is<cr>My<cr>Sentence"

Can anybody tell me what I need to put in there please? It needs to be included within the field in the table, splitting it out afterwards would be far too complicated.

Thanks
Raistlin is offline   Reply With Quote
Advertisement
Old 19-08-2005, 20:44   #2
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: A little SQL help (possibly)

You can, but not in SQL. SQL functions are fairly limited, but include maths ones like max, min, avg, count, etc.

You'd have to get the value with a SELECT query as per normal, and then parse the result as you want it to display.

What DBMS/Language are you using with the SQL? VB? PHP? Access?
punky is offline   Reply With Quote
Old 19-08-2005, 20:46   #3
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: A little SQL help (possibly)

Cheers matey, but (as is always the way) I've just solved it.

I'm trying to put information into an Info Window in Google Maps, the info window uses HTML.....so.....all I have to do is include <BR> between each word and it gives me a new line

Thanks though.
Raistlin is offline   Reply With Quote
Old 19-08-2005, 21:07   #4
philip.j.fry
Inactive
 
philip.j.fry's Avatar
 
Join Date: Jul 2003
Posts: 1,395
philip.j.fry has reached the bronze age
philip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze agephilip.j.fry has reached the bronze age
Re: A little SQL help (possibly)

For future reference there are special characters you need for newlines, these differ between windows, macs and *nixes.

There are two escape characters that you need to know, \n is the line feed (LF) character and \r is the carriage return (CR) character.

*nixes use just the LF character for a newline: e.g "This\nIs\nMy\nSentence"

Windows uses the CR followed by the LF character: e.g. "This\r\nIs\r\nMy\r\nSentence"

Macs use just the CR. e.g. "This\rIs\rMy\rSentence"

These are normal characters and will store fine in a database. Most modern programming languages have a constant that represents the newline character for the system you are using.
philip.j.fry is offline   Reply With Quote
Old 19-08-2005, 21:22   #5
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: A little SQL help (possibly)

Thanks for that. I tried \r but the database kept putting another \ in front of it.

I didn't try \r\n though, that's probably where I was going wrong.....
Raistlin is offline   Reply With Quote
Old 20-08-2005, 01:06   #6
greencreeper
Inactive
 
Join Date: Nov 2003
Location: Leeds - the dog house
Age: 49
Services: Email me for a current price list
Posts: 8,270
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
Re: A little SQL help (possibly)

Bit late but... You shouldn't store formatting - just data. Formatting is done at the point the viewer views. That way you (or the viewer) can change the formatting dependant on, say, who's viewing it or how it's viewed.
greencreeper is offline   Reply With Quote
Old 20-08-2005, 01:08   #7
Raistlin
Inactive
 
Join Date: Feb 2004
Location: There's no place like 127.0.0.1
Services: Depends on the person and the price they're offering
Posts: 12,384
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Raistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered starsRaistlin is seeing silvered stars
Re: A little SQL help (possibly)

Quote:
Originally Posted by greencreeper
Bit late but... You shouldn't store formatting - just data. Formatting is done at the point the viewer views. That way you (or the viewer) can change the formatting dependant on, say, who's viewing it or how it's viewed.
Needs to be stored unfortunately, if it's not the different values all bleed into one on one long line and it throws the Info Box for the Marker out
Raistlin is offline   Reply With Quote
Old 20-08-2005, 01:39   #8
punky
Inactive
 
Join Date: Jun 2003
Age: 45
Posts: 14,750
punky has a golden aurapunky has a golden aura
punky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aurapunky has a golden aura
Re: A little SQL help (possibly)

BTW in case you are missing out on something obvious here Raist:

SQL can store carriage returns and whatever you use to query your DB with, can handle it.

For example, you can have a LONGTEXT or VARCHAR in MySql which is linked a textarea HTML element. If you put carriage returns in your textarea, MySql will save them, but when you display them again, say with PHP, HTML takes over and ignores them because it doesn't see <br>s. However, don't forget you can use the <pre> </pre> HTML element tags, which ignores standard HTML formatting so carriage returns are outputted. The <pre> styles can be set with stylesheets or style tags just like any other HTML element.
punky is offline   Reply With Quote
Old 20-08-2005, 03:42   #9
Richard M
Inactive
 
Join Date: Jun 2003
Location: Los Angeles, CA
Age: 47
Posts: 6,343
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Richard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze arrayRichard M has a bronze array
Re: A little SQL help (possibly)

Quote:
Originally Posted by punky
BTW in case you are missing out on something obvious here Raist:

SQL can store carriage returns and whatever you use to query your DB with, can handle it.

For example, you can have a LONGTEXT or VARCHAR in MySql which is linked a textarea HTML element. If you put carriage returns in your textarea, MySql will save them, but when you display them again, say with PHP, HTML takes over and ignores them because it doesn't see <br>s. However, don't forget you can use the <pre> </pre> HTML element tags, which ignores standard HTML formatting so carriage returns are outputted. The <pre> styles can be set with stylesheets or style tags just like any other HTML element.
Sounds like he's using MSSQL to me though...
Richard M is offline   Reply With Quote
Old 20-08-2005, 21:41   #10
greencreeper
Inactive
 
Join Date: Nov 2003
Location: Leeds - the dog house
Age: 49
Services: Email me for a current price list
Posts: 8,270
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
greencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny stargreencreeper has a nice shiny star
Re: A little SQL help (possibly)

Quote:
Originally Posted by Raistlin
Needs to be stored unfortunately, if it's not the different values all bleed into one on one long line and it throws the Info Box for the Marker out
It's not possible to format the data after you retrieve it from the database, but before you display it?
greencreeper is offline   Reply With Quote
Old 21-08-2005, 00:49   #11
Paddy1
cf.addict
 
Join Date: Jul 2004
Posts: 352
Paddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond reputePaddy1 has a reputation beyond repute
Re: A little SQL help (possibly)

Store the individual words rather than the sentence. e.g.


My Table
-----------
SentenceId
WordNo
Word

Data
SentenceId WordNo Word
1 1 This
1 2 is
1 3 my
1 4 sentence

Then

Select Word
From my_table
Where SentenceId = 1
Order By WordNo
Paddy1 is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 19:08.


Server: lithium.zmnt.uk
Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2026, vBulletin Solutions Inc.
All Posts and Content are © Cable Forum