Login [Register]
Don't have an account? Register now to chat, post, use our tools, and much more.
This is an archived, read-only copy of the United-TI subforum , including posts and topic from May 2003 to April 2012. If you would like to discuss any of the topics in this forum, you can visit Cemetech's Calculator Programming subforum. Some of these topics may also be directly-linked to active Cemetech topics. If you are a Cemetech member with a linked United-TI account, you can link United-TI topics here with your current Cemetech topics.

This forum is locked: you cannot post, reply to, or edit topics. General Coding and Design => Calculator Programming
Author Message
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 25 Aug 2009 04:14:28 pm    Post subject:

How do you store information into a table that takes up two lines (has a carriage return in it)?

Example:

Line of text

Line of text

Be able to add that to a database and recall it so it looks the same.
Back to top
Graphmastur


Advanced Member


Joined: 25 Mar 2009
Posts: 360

Posted: 25 Aug 2009 05:51:06 pm    Post subject:

I am not sure, but you might be able to use the escape character "\n".

I haven't done SQL in forever, so...
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 25 Aug 2009 05:59:10 pm    Post subject:

It appears it does it automatically. My problem was I was using VARCHAR which only allows for 255 characters. I tried using LONGTEXT, but it will not let me create a table with that data type for some reason.
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 25 Aug 2009 06:27:22 pm    Post subject:

What sort of data are you storing? If you're writing a web application that just needs to display the text with the line breaks, then using HTML format <br /> tags is the best way to go. Or, if the data on each line is a separate entity, they can be stored in two columns instead, and the newline added in whenever the text must be displayed. But that's your call how the data should be stored.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 25 Aug 2009 06:53:24 pm    Post subject:

I need to store like a blog like post. The only reason I need the line breaks is for paragraphs and that's it. Is there a way to get php to show the breaks when it calls the data from the database.

ie

<?php
// Make a MySQL Connection
mysql_connect("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("test") or die(mysql_error());

$query = "SELECT * FROM example";

$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['data'];
?>

That grabs all the text which appears to have the line breaks in the database, but it displays it as if there are no breaks.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 25 Aug 2009 07:19:17 pm    Post subject:

I tried the breakout \n. It worked in the database but not with the php.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 26 Aug 2009 09:33:47 am    Post subject:

Thanks. I fixed the issue using a string replace.

Quick question though. I have the ID auto increment for each data entry. If I delete an entry how do I get it so it will shift everything down?

What I mean is If I have 5 items 1-5 and I delete 4 it will be like 1, 2, 3, 4, and not 1, 2, 3, 5?
Back to top
magicdanw
pcGuru()


Calc Guru


Joined: 14 Feb 2007
Posts: 1110

Posted: 26 Aug 2009 09:46:31 am    Post subject:

Don't. Ever. The point of an autoincrementing ID is so that every item will have a unique ID FOREVER. Even if it's deleted. You use the IDs to reference records in other tables (cross-referencing), and so it can't change. IDs should only be used to identify a record, and if you want something to order the items, use another column, such as a date column, or a position column, or whatever you need.
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 26 Aug 2009 09:49:10 am    Post subject:

Oh OK. Thanks. I'll just timestamp my records then.

Edit: Not records, but items. Smile


Last edited by Guest on 26 Aug 2009 09:49:55 am; edited 1 time in total
Back to top
benryves


Active Member


Joined: 23 Feb 2006
Posts: 564

Posted: 26 Aug 2009 11:11:54 am    Post subject:

With regard to turning ASCII newlines into HTML breaks, see the PHP nl2br() function (I know you already solved this, but always nicer to use a built-in function than straight string replacement).

Last edited by Guest on 05 Jul 2010 08:10:18 am; edited 1 time in total
Back to top
Newbie


Bandwidth Hog


Joined: 23 Jan 2004
Posts: 2247

Posted: 26 Aug 2009 11:22:19 am    Post subject:

Thanks benryves! I"m actually going to do that as it will get rid of a lot of extra lines of code for a much simpler way of doing it.

Just applied it. I'll take one line of code over three any day. Smile


Last edited by Guest on 26 Aug 2009 11:24:26 am; edited 1 time in total
Back to top
Display posts from previous:   
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
    »
» View previous topic :: View next topic  
Page 1 of 1 » All times are GMT - 5 Hours

 

Advertisement