eramge11 Posted December 18, 2014 Share Posted December 18, 2014 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; 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. 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> Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/ Share on other sites More sharing options...
NotionCommotion Posted December 18, 2014 Share Posted December 18, 2014 You have an input which is sending content as text. Later you take that content and display it as HTML. I bet nl2br will make you happy Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1499953 Share on other sites More sharing options...
eramge11 Posted December 18, 2014 Author Share Posted December 18, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1499955 Share on other sites More sharing options...
Ch0cu3r Posted December 18, 2014 Share Posted December 18, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1499971 Share on other sites More sharing options...
eramge11 Posted December 19, 2014 Author Share Posted December 19, 2014 It is not working for me! I tested it and it's not showing up. However, I found that if I type <br> into the notes section when I am adding notes it will space the thing but I really would like it to do it automatically. Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500041 Share on other sites More sharing options...
eramge11 Posted December 19, 2014 Author Share Posted December 19, 2014 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> Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500045 Share on other sites More sharing options...
Ch0cu3r Posted December 19, 2014 Share Posted December 19, 2014 Try <td class="table-cell-title">NARRATIVE</td> <td class="table-cell-content"> <?php echo (!empty($studInfo->Rel_Stud_Info->student_guardian_occupation_address) ? nl2br($studInfo->Rel_Stud_Info->student_guardian_occupation_address) : "Not Set"); ?></td> Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500073 Share on other sites More sharing options...
eramge11 Posted December 19, 2014 Author Share Posted December 19, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1500085 Share on other sites More sharing options...
eramge11 Posted January 3, 2015 Author Share Posted January 3, 2015 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? Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1501566 Share on other sites More sharing options...
Ch0cu3r Posted January 3, 2015 Share Posted January 3, 2015 Where you use $StudentInfo->student_guardian_occupation_address <td class="label">BODY</td><td colspan="3"><?php echo nl2br($StudentInfo->student_guardian_occupation_address);?></td> Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1501606 Share on other sites More sharing options...
CroNiX Posted January 3, 2015 Share Posted January 3, 2015 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. Quote Link to comment https://forums.phpfreaks.com/topic/293160-help-with-text/#findComment-1501622 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.