zako234 Posted December 26, 2007 Share Posted December 26, 2007 Hey, I have a small problem related to php and mysql. I'm working on a database where users enter an aim chat into a text box, and submit it to a mysql database. When I attempt to retrieve the chat, the browser displays it all in one line, as opposed to on separate lines as it normally would. Example below: Zako i: we have hotdogs wakebrd: richie will bring them up to me Zako i: haha becomes Zako i: we have hotdogs wakebrd: richie will bring them up to me Zako i: haha When i look in my database using phpmyadmin, it looks normally formatted and has no issue, but when i retrieve the string the problems start, could anyone help? For entering: $sn1 = chop($_POST['USN1']," :"); $sn2 = chop($_POST['USN2']," :"); $chat = $_POST['Chat']; $user = Trim($_POST['uid'],"'."); include 'dbconfig.php'; // CHATID, UID, SN1, SN2, CHAT, RATING $q = "INSERT INTO users_chats VALUES('','$user', '$sn1','$sn2','$chat','','')"; For displaying: // get everything form the table $q = 'SELECT * FROM `users_chats` WHERE UID = "'.$user.'" ORDER BY `ID` DESC'; // get the result $result = query($q); // if there's nothing in your table, say something if (mysql_num_rows($result) == 0){ echo ' go add some chats'; }else{ // if not, go on echo '<table>'; // counter i reaches the nubmber of rows while ($i != mysql_num_rows($result)+1){ // get an array for each row while ($a_row = mysql_fetch_assoc($result) ) { echo '<tr>'; echo '<td>'.$a_row[sN1].'</td>'; echo '<td>'.$a_row[sN2].'</td>'; echo '<td>'.$a_row[CHAT].'</td>'; echo '</tr>'; } echo '</table>'; Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/ Share on other sites More sharing options...
trq Posted December 26, 2007 Share Posted December 26, 2007 Post the relevant code. Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423170 Share on other sites More sharing options...
zako234 Posted December 26, 2007 Author Share Posted December 26, 2007 code posted in edit Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423172 Share on other sites More sharing options...
trq Posted December 26, 2007 Share Posted December 26, 2007 This part.... while ($a_row = mysql_fetch_assoc($result) ) { echo '<tr>'; echo '<td>'.$a_row[sN1].'</td>'; echo '<td>'.$a_row[sN2].'</td>'; echo '<td>'.$a_row[CHAT].'</td>'; echo '</tr>'; } which by the way should be.... while ($a_row = mysql_fetch_assoc($result) ) { echo '<tr>'; echo '<td>'.$a_row['SN1'].'</td>'; echo '<td>'.$a_row['SN2'].'</td>'; echo '<td>'.$a_row['CHAT'].'</td>'; echo '</tr>'; } Creates a new table row for each record. I don't see what your issue is. Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423176 Share on other sites More sharing options...
zako234 Posted December 26, 2007 Author Share Posted December 26, 2007 The text goes in as a normal pagraph, with line breaks. And is visible in phpmyadmin as normal text with line breaks, but when i request it, it is rendered on my page as one single very long sentence without any line breaks. Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423186 Share on other sites More sharing options...
trq Posted December 26, 2007 Share Posted December 26, 2007 nl2br() may be what your looking for. Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423190 Share on other sites More sharing options...
zako234 Posted December 26, 2007 Author Share Posted December 26, 2007 thanks! worked great! Link to comment https://forums.phpfreaks.com/topic/83192-solved-string-formatting-issue/#findComment-423209 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.