doforumda Posted August 16, 2011 Share Posted August 16, 2011 Hi, I am trying to display text from database in proper format but it is not working the way I want. First here is how the data is stored in database table in "desc" column [p]Today we are going to learn how can we connect to mysql database using php. It is very important to know because connecting to database is the backbone of any web application.[p] [p]So here you go![p] [p]Below is the sample code for connecting to database. Explanation for this demo is below the code[p] [c] $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); [c] [p]So the first two lines are enough for connecting to database. Whereas the third line is only for querying database table to get records from a table table_name[p] [p]This was today's tutorial. Hope you like it. If you like it then like us on facebook.[p] [c] $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); [c] and here is how I am trying to display it <?php $p = string_between($desc,'[p]'); ?> <?php $c = string_between($desc,'[c]'); ?> <?php $total = count($p) + count($c); ?> <?php for($i = 0; $i < $total; $i++) : ?> <?php if(isset($p[$i]) && $p[$i] != "") { ?> <?php echo "<p>" . $p[$i] . "</p>" ?> <?php } ?> <?php if(isset($c[$i]) && $c[$i] != "") { ?> <?php echo "<p><pre class='prettyprint'>" . $c[$i] . "</pre></p>" ?> <?php } ?> <?php endfor; ?> so this code displays data in this format Today we are going to learn how can we connect to mysql database using php. It is very important to know because connecting to database is the backbone of any web application. $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); So here you go! $connect = mysql_connect("localhost","username","password"); $database = mysql_select_database("database_name"); $query = mysql_query("SELECT * FROM table_name"); Below is the sample code for connecting to database. Explanation for this demo is below the code So the first two lines are enough for connecting to database. Whereas the third line is only for querying database table to get records from a table table_name This was today's tutorial. Hope you like it. If you like it then like us on facebook. As you can see the code is displaying in the wrong place. the first block of code should be displayed after third paragraph. And the second block of code should be displayed at the end because the blocks are stored in this way. How can I display it the way it is in database? help! Quote Link to comment https://forums.phpfreaks.com/topic/244908-need-help-in-displaying-text-from-database-in-proper-format/ 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.