Jump to content

Recommended Posts

Hello everyone! I will try to make this as easy as possible to understand. I have a database that we use in PHP attached to our website that keeps a detailed log of each member. We just recently added a section to the database that allows for notes to be added to the members record. However, each time we type something it does not take the spaces or anything into consideration. Let me show you with pictures:

 

1. This is what the database looks like when you are typing the notes into the members profile;

 

Report1_zpsc62316ee.jpg

 

Once you click save and go to the member's "Overview" this is what the notes section looks like;

you can see that the text is there but it stays in a block format and does not take any spacing/formatting into consideration. The more you type the worse and blocky it looks.

 

Report2_zps6e6a8a8b.jpg
The biggest problem is that we have an option to geneate the report into a PDF. It looks horrible when the notes are blocked and not formatted correctly with spaces ect. I believe my SQL table is currently set to VCHAR (100) and the php file is telling the command to read everything as text. Does anyone know what I need to do to keep the formatting. I am pretty new to all of this so if someone could take a few minutes and explain a little bit to me that would be great. I am quite honestly five seconds from pulling my hair out.

 

 

For anyone who cares this is what the PHP code looks like for the table;

	<div class="row">
		<?php echo $form->labelEx($info,'student_notes'); ?>
		<?php echo $form->textArea($info,'student_notes',array('size'=>59,'maxlength'=>500,'style'=>'width:1503px;height:340px;margin-bottom:15px')); ?><span class="status"> </span>
		<?php echo $form->error($info,'student_notes'); ?>
	</div>

Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/
Share on other sites

Hello! What exactly do you suggest I change? I have never used nl2br before. If you could maybe give me a little explination that would help me out tremendously. I basically want to be able to type my notes and the spaces automatically translate to the PDF and overview screen. If that makes any sense from what I posed above.

Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1499955
Share on other sites

You use nl2br when you go to output your data.

 

Small example

<?php

if(isset($_POST['submit']))
{
    echo nl2br($_POST['my_data']); // output data entered into textarea
    echo '<hr />';
}

?>
<form method="post">
   <textarea name="my_data" rows="10" cols="100"><?php echo isset($_POST['my_data']) ? $_POST['my_data'] : ''; ?></textarea>
   <input type="submit" name="submit" value="Submit" />
</form>
Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1499971
Share on other sites

Someone told me my problem is as you said needing to add nl2br into my code. I am struggling extremely on trying to get this figured out. Below is my HTML for viewing the notes section and the PHP code that is making it work. Could someone possibly edit it and show me what I need to do correctly. As I said I am new and doing this so any guidance is appreciated.

 

PHP:

	<div class="row">
		<?php echo $form->labelEx($info,'student_guardian_occupation_address'); ?>
		<?php echo $form->textArea($info,'student_guardian_occupation_address',array('size'=>59,'maxlength'=>500,'style'=>'width:1200px;height:340px;margin-bottom:15px')); ?><span class="status"> </span>
		<?php echo $form->error($info,''); ?>
	</div>

Here is the HTML code for viewing it:

<td class="table-cell-title">NARRATIVE</td>
                                    <td class="table-cell-content"> <?php echo (!empty($studInfo->Rel_Stud_Info->student_guardian_occupation_address) ? $studInfo->Rel_Stud_Info->student_guardian_occupation_address : "Not Set"); ?></td>
Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500045
Share on other sites

You are amazing! It worked perfectly! My final question and to get out of your hair with this- I have my SQL tables set to VCHAR (1000) characters. However, when I type something it cuts me off at 100 characters and won't let any more characters go. Maybe you could shine some light on this.

Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500085
Share on other sites

  • 2 weeks later...

I am now trying to get the nl2br to work with my PDF final view when I go to print a report.

 

Here is the code:

<td class="label">BODY</td><td colspan="3"><?php echo $StudentInfo->student_guardian_occupation_address;?></td>

Where would I put the nl2br in this case?

Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1501566
Share on other sites

You use nl2br() when you OUTPUT the stored data from the database. It converts the hidden line breaks (\n) that occur when hitting return in a textarea (and others form controls) back into HTML <br />'s. In your database they are stored as \n but you can't see them when viewing directly, as they're hidden control characters.

Link to comment
https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1501622
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.