[PHP] help with nl2br
I have cobbled the following code that when it retrieves the data from Mysql, the data is displayed with no line breaks which results in one large paragraph. I have been trying for quite awhile without sucess to get nl2br working with this code. The original data is entered by the user via a textarea form. Any help would be much apreciated...I am still fairly new at programming and it probably shows... Thanks TD. ?php // set database server access variables: $host = localhost; $user = develop; $pass = ; $db = bio; // open connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // create query $query = SELECT * FROM main; // execute query $result = mysql_query($query) or die (Error in query: $query. .mysql_error()); // see if any rows were returned if (mysql_num_rows($result) 0) { // yes // print them one after another echo table cellpadding=0 width = 100% border=0; while($row = mysql_fetch_row($result)) { echo trfont color=blue size =4; echo .$row[1]/b; echo trfont color=black size = 3; echo .$row[2]; echo br \n; echo br \n; } } else { // no // print status message echo No rows found!; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?
Re: [PHP] help with nl2br
Thanks Pablo, that did the trick with one minor change, I had to remove the . in the quotations as it is was leading the first line of text with a . echo . nl2br($row[2]) . /b; TD. On 3/3/06, Pablo M. Rivas [EMAIL PROTECTED] wrote: Hello canobit: Did you try echo . . nl2br($row[1]) . /b; ?? On 3/2/06, canobit canobit [EMAIL PROTECTED] wrote: I have cobbled the following code that when it retrieves the data from Mysql, the data is displayed with no line breaks which results in one large paragraph. I have been trying for quite awhile without sucess to get nl2br working with this code. The original data is entered by the user via a textarea form. Any help would be much apreciated...I am still fairly new at programming and it probably shows... Thanks TD. ?php // set database server access variables: $host = localhost; $user = develop; $pass = ; $db = bio; // open connection $connection = mysql_connect($host, $user, $pass) or die (Unable to connect!); // select database mysql_select_db($db) or die (Unable to select database!); // create query $query = SELECT * FROM main; // execute query $result = mysql_query($query) or die (Error in query: $query. .mysql_error()); // see if any rows were returned if (mysql_num_rows($result) 0) { // yes // print them one after another echo table cellpadding=0 width = 100% border=0; while($row = mysql_fetch_row($result)) { echo trfont color=blue size =4; echo .$row[1]/b; echo trfont color=black size = 3; echo .$row[2]; echo br \n; echo br \n; } } else { // no // print status message echo No rows found!; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ? -- Pablo M. Rivas. http://www.r3soft.com.ar http://www.tres-erres.com.ar ---
Re: [PHP] help with nl2br
snip All that said, you might want to invest some time in learning a DB abstraction layer such as ADODb or PEAR::DB (there are lots of others). You'll commonly find convenience functions to do things like output query results into an HTML table. Why waste time debugging the wheel? -- Max Schwanekamp http://www.neptunewebworks.com/ Thanks Max, I will further look into look into this. PEAR::DB looks interesting! TD