Jump to content

Recommended Posts

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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