Jump to content

[SOLVED] String formatting issue


zako234

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.