khristian Posted March 20, 2008 Share Posted March 20, 2008 Hi people, I use a PHP form to store information in an SQL database, this al works fine until I try and pull the information back. When I enter the information in a textarea box it is then stored in a 'text' field in the database. When I pull it back I use: print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['issue'].'</td>'; Okay so this does pull back the information, but it does not include line breaks, so for example if I stored this post in my database then I would just get it all back as one line, even though when I use phpmyadmin I can see the text box with the empty lines. Any ideas? Link to comment https://forums.phpfreaks.com/topic/97162-php-sql-form-issue/ Share on other sites More sharing options...
CMC Posted March 20, 2008 Share Posted March 20, 2008 nl2br. This will convert newlines to <br /> (the HTML equivalent) so when the data is returned, the browser will interpret it accordingly. You could also use str_replace. ex: <?php $replace = str_replace("\n","<br />",$row['issue']); ?> Link to comment https://forums.phpfreaks.com/topic/97162-php-sql-form-issue/#findComment-497176 Share on other sites More sharing options...
khristian Posted March 20, 2008 Author Share Posted March 20, 2008 Cheers, but how would I put that into effect. My full code at the moment is: <? $sql = "SELECT * FROM status WHERE recordid = '$issuenumber';"; $result = mysql_query($sql); { while($row = mysql_fetch_array($result)) { print '<table border="0" width="100%" id="table1" cellspacing="0" cellpadding="0">'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Issue affecting:</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['affecting'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Issue description</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['issuetitle'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Issue details</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['issue'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Reported to:</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['reportedto'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Reported:</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['reporteddate'].' @ '.$row['reportedtime'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Estimated repair date:</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['fixdate'].'</td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"> </td>'; print ' </tr>'; print ' <tr>'; print ' <td width="40%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0"><b>Status:</b></td>'; print ' <td width="60%" valign="top">'; print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.$row['status'].'</td>'; print ' </tr>'; print '</table>'; } } ?> Link to comment https://forums.phpfreaks.com/topic/97162-php-sql-form-issue/#findComment-497210 Share on other sites More sharing options...
khristian Posted March 21, 2008 Author Share Posted March 21, 2008 Okay I got it worked out by using: print ' <p class="main" style="margin-top: 0; margin-bottom: 0">'.nl2br($row['issue']).'</td>'; Link to comment https://forums.phpfreaks.com/topic/97162-php-sql-form-issue/#findComment-497270 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.