Jump to content


PHP/MySql Problem


6 replies to this topic

#1 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 11 May 2007 - 07:07 PM

Ok here is a test info. of what is put in the database. It is put in a column named info.
/////////////////////////
The name is John.

John hates dogs.

Dogs must die.
/////////////////////////
Now I want to display that whole thing on my page(in an textarea of a form). This is my snippet.
<textarea name="info" rows="15" id="msg" cols="51" />
  <?php echo $row['info']; ?>
</textarea>
It works great for one line but it doesnt read anymore. It stops when it gets to the whitespace. I've been looking for a solution on php.net but all I can find is the strip_whitespace. Below is an example of what it outputs on my page
////////////////////////////
The name is John.
////////////////////////////
That's all it outputs. Any would would be greatly appreciated.

#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 11 May 2007 - 07:21 PM

Is your MYSQL column a text field?

#3 Demonslay

    P2L Jedi

  • Members
  • PipPipPip
  • 970 posts
  • Gender:Male
  • Location:A strange world where water falls out of the sky... for no reason.
  • Interests:Graphic Design, Coding, Splinter Cell, Cats

Posted 11 May 2007 - 08:49 PM

If you're looking for a proper line breaking, use nl2br().

Check that your table column is a text type, that it has a large anough storage length, and also that you are looping correctly.

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 May 2007 - 12:39 AM

First thing. Proper XHTML doesn't require the shorthand closing tag if the tag has an actual closing tag, like textarea does.
<textarea name="info" id="msg" rows="15" cols="51"><?php
echo $row['info'];
?></textarea>

Second, check your source, make sure it's not an html problem. If it is, then what i did may or may not fix the problem.

#5 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 12 May 2007 - 03:39 PM

I haven't been able to test any of the suggestions you guys sent me. My MySql went down right after my first post on the forum.

Av-
The MySql column is of type text.

Demonslay
How would I integrate that nl2br? Would it be when entering the information into the database? Also what do you
mean by looping? How/why would I loop this?

rc69
I did what you told me. I also checked the source code and couldn't find any issues in it. Would you like me to send
it? The only problem is it is a huge file.

Possibly anymore suggestions? Just in case. Is there a way I can use something like the "getline" snippet in c++? Use it like a loop where it gets the line then i tell it to go to the next line. Kind of a stupid concept I know, but I figured "brute force" might make it get everything.

#6 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 12 May 2007 - 04:37 PM

nl2br is used to convert new line characters (\n) into breaks for display on html pages. It is basically what most forum or any other kind of system uses to display when the enter button was pressed.

What demonslay is trying to do is make sure the info was stored in the database. If you go to phpMyAdmin and view the column you are trying to display, is all of the text you want displayed there? Then when he refers to looping, i'm assuming that he is assuming you are using a loop to retrieve info from the database. If you are using a textarea for display, i'm assuming you aren't using a loop, so you shouldn't have to worry to much.

The source code i'm talking about is the HTML, not the PHP. Once you fix your mysql and load the page, right click>view source. All of the text should be there, if it's not, then we have a problem. If it is and the textarea still isn't displaying it, then we have another problem.

#7 Korndawg

    Young Padawan

  • Members
  • Pip
  • 111 posts
  • Gender:Male
  • Location:Texas, USA

Posted 12 May 2007 - 04:41 PM

All the info. is being saved into the column as I typed it when entering it. It has the lines set up perfectly and doesnt skip anything. Just for some reason it isn't pulling all the information from the database. It only grabs the 1st line then it quits.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users